nse data fetch issue
Issue: can't able to fetch index history using index_history function
ERROR:
"""
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/nsepython/rahu.py in index_history(symbol, start_date, end_date) 746 data = "{'name':'"+symbol+"','startDate':'"+start_date+"','endDate':'"+end_date+"'}" 747 payload = requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, data=data).json() --> 748 payload = json.loads(payload["d"]) 749 payload=pd.DataFrame.from_records(payload) 750 return payload
KeyError: 'd' """
note: payload = requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers, data=data).json()
payload={'Message': 'There was an error processing the request.', 'StackTrace': '', 'ExceptionType': ''}
I'm running into the same issue @aeron7
replace index_history function with below function body in rahu.py
def index_history(symbol,start_date,end_date):
data = {"name": symbol,
"startDate": start_date,
"endDate": end_date,
}
data={"cinfo":json.dumps(data)}
payload = requests.post('https://www.niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', timeout=300, headers=niftyindices_headers, json=data,).json()
payload = json.loads(payload["d"])
payload=pd.DataFrame.from_records(payload)
return payload
replace index_history function with below function body in rahu.py
def index_history(symbol,start_date,end_date): data = {"name": symbol, "startDate": start_date, "endDate": end_date, } data={"cinfo":json.dumps(data)} payload = requests.post('https://www.niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', timeout=300, headers=niftyindices_headers, json=data,).json() payload = json.loads(payload["d"]) payload=pd.DataFrame.from_records(payload) return payload
This is working. Thanks
https://github.com/aeron7/nsepython/pull/40 will take care of this @aeron7
Support and Beta Functions If you have other doubts or want to check out the beta functions, visit the NSEPython Discussions forum. If you have feature requests, you can submit them at the NSEPython Feature Request forum.