I am getting error while calling index_history api. I am using python 3.10 and 2.8 version of nsepython.
import nsepython
nsepython.index_history(‘NIFTY 50’, ‘2024-03-01’, ‘2024-03-14’)
Traceback (most recent call last):
File “/snap/pycharm-community/374/plugins/python-ce/helpers/pydev/pydevconsole.py”, line 364, in runcode
coro = func()
File “”, line 1, in
File “/home/gurvinder/.local/lib/python3.10/site-packages/nsepython/rahu.py”, line 748, in index_history
payload = json.loads(payload[“d”])
KeyError: ‘d’
can someone please help?
1 Like
Still getting the error with this syntax.
1 Like
dexter
4
Put in Google Collab using nsepythonserver.
Try.
If you fail, share that collab link here, I will check.
line
755, in index_pe_pb_div
payload = json.loads(payload[“d”])
~~~~~~~^^^^^
KeyError: ‘d’
dexter
6
Keyerror. Hmm. It means it is returning blank data.
Have you updated NSEpython to its latest version?
yes updated the library. it was working fine before but stopped working since few days back.
from nsepython import *
symbol = “NIFTY 50”
start_date = “01-Mar-2011”
end_date = “07-Jun-2021”
print(index_pe_pb_div(symbol,start_date,end_date))
output:
line 755, in index_pe_pb_div
payload = json.loads(payload[“d”])
~~~~~~~^^^^^
KeyError: ‘d’
dexter
8
Unable to debug as it works fine for me surprisingly. Try the nsepythonserver in Google Collab, You will see it works.
Whats your stack
hi
could you share the working g colab file for the same ?
pfa of my g colab:
dexter
10
will give tomorrow in phone.
Hi
any updates on the same ? or could you share the working colab. ?
dexter
12
Wait. Haven’t reached home. I am hyper active person don’t worry. Will give tomorrow.
Hi
Any updates dear , your api work is great, would it take time
dexter
14
Tried to see once. Your collab said I don’t have access. So I forgot afterwards. They may have changed something in middle.
Use this for meanwhile.
import requests
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'en-US,en;q=0.9',
'Connection': 'keep-alive',
'Content-Type': 'application/json; charset=UTF-8',
'DNT': '1',
'Origin': 'https://niftyindices.com',
'Referer': 'https://niftyindices.com/reports/historical-data',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
json_data = {
'cinfo': "{'name':'NIFTY 50','startDate':'01-Jan-2023','endDate':'26-Apr-2024'}",
}
response = requests.post(
'https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString',
headers=headers,
json=json_data,
)
response.text