I am fetching some data from an API and saving the contents of response JSON to a list. However i am getting "'NoneType' object is not subscriptable" error. I understood that i am indexing a none object. How do i resolve it? I am pretty new to Python.
for i in range(0,len(content)):
try:
response = requests.post(url, data=json.dumps({
"GetSignificantDevelopments_Request_1": {
"FindRequest": {
"CompanyIdentifiers_typehint": [
"CompanyIdentifiers"
],
"CompanyIdentifiers": [
{
"RIC": {
#"Value": content[i]
"Value": "8341.T"
}
}
],
"StartDate": "2020-08-01T00:00:00",
"EndDate": "2020-09-21T00:00:00",
"Significance": "1 2 3",
"MaxNumberOfItems": 2000
}
}
}), headers=headers)
data=json.loads(response.text.encode('utf8'))
for item in data['GetSignificantDevelopments_Response_1']['FindResponse']['Development']:
list_RepNo=[]
list_DevelopmenId=[]
list_RepNo.append(item['Xrefs']['RepNo'])
list_DevelopmenId.append(item['Xrefs']['DevelopmentId'])
except Exception as Error:
print(Error)
raise
continue
The error which i am getting is below:
'NoneType' object is not subscriptable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-c73ee1d65472> in <module>
36 }), headers=headers)
37 data=json.loads(response.text.encode('utf8'))
---> 38 for item in data['GetSignificantDevelopments_Response_1']['FindResponse']['Development']:
39 list_RepNo=[]
40 list_DevelopmenId=[]
TypeError: 'NoneType' object is not subscriptable
How do i resolve this?