Getting an error


KeyError Traceback (most recent call last)
in <cell line: 4>()
2 start_date = “01-Mar-2011”
3 end_date = “07-Jun-2021”
----> 4 print(index_history(symbol,start_date,end_date))

/usr/local/lib/python3.10/dist-packages/nsepython/rahu.py in index_history(symbol, start_date, end_date)
747 payload = requests.post(‘https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString’, headers=niftyindices_headers, data=data).json()
748 # print(payload)
→ 749 payload = json.loads(payload[“d”])
750 payload=pd.DataFrame.from_records(payload)
751 return payload

KeyError: ‘d’

2 Likes

There is a change in NIFTY Indicies website. So We need to update the wrapper accordingly.

Refer to this temporary workaround. Within 24 hours a new Wrapper update is expected. It will be solved in that update.

1 Like

Hello there,

See in my opinion It seems that there is an issue with accessing the ‘d’ key in the JSON response. It is likely that the JSON structure returned by the API has changed or there might be a typo in the key.

Also, Double check the API documentation or the response structure to ensure that you are accessing the correct key.

Hope this could help in resolving your query.

As said earlier, There is a change in NIFTY Indicies website.

It will be fixed in this update.

Waiting for the update and thanks for sparing a time mate.

waiting for the new api dear

Starting on it.

I did on your google collab only. It was so easy then… Its still easy now.

They have changed the JSON structure.

Why this takes time… and attention… normal stuff bro

def index_history(symbol,start_date,end_date):
    data = {'cinfo': "{'name':'" + symbol + "','startDate':'" + start_date + "','endDate':'" + end_date + "','indexName':'" + symbol + "'}"}
    payload = requests.post('https://niftyindices.com/Backpage.aspx/getHistoricaldatatabletoString', headers=niftyindices_headers,  json=data).json()
    payload = json.loads(payload["d"])
    payload=pd.DataFrame.from_records(payload)
    return payload

def index_pe_pb_div(symbol,start_date,end_date):
    data = {'cinfo': "{'name':'" + symbol + "','startDate':'" + start_date + "','endDate':'" + end_date + "','indexName':'" + symbol + "'}"}
    payload = requests.post('https://niftyindices.com/Backpage.aspx/getpepbHistoricaldataDBtoString', headers=niftyindices_headers,  json=data).json()
    payload = json.loads(payload["d"])
    payload=pd.DataFrame.from_records(payload)
    return payload

def index_total_returns(symbol,start_date,end_date):
    data = {'cinfo': "{'name':'" + symbol + "','startDate':'" + start_date + "','endDate':'" + end_date + "','indexName':'" + symbol + "'}"}
    payload = requests.post('https://niftyindices.com/Backpage.aspx/getTotalReturnIndexString', headers=niftyindices_headers,  json=data).json()
    payload = json.loads(payload["d"])
    payload=pd.DataFrame.from_records(payload)
    return payload

Three functions will be fixed.

PS - Update NSEPython. Refer https://unofficed.com/nse-python/documentation/#getting-started on how to. or Google out. It should work fine.