I keep getting a keyerror in python.
I am using requests and getting back a json with 3 values. I am trying to extract only the elevation.
r = requests.get(api_url +str(lat) +"," +str(longi) )
resp = json.loads(r.text)
print(resp)
print(resp['elevation'])
this is the response for resp:
{'results': [{'latitude': 30.654543, 'longitude': 35.235351, 'elevation': -80}]}
this is the error:
KeyError: 'elevation'
print(resp['results'][0]['elevation'])?respis, to say so, a dictionary with included list with included dictionary.resp["results"]returns you the list;resp["results"][0]returns you the first element of this list and it is the dictionary, and inside this dictionary there is the keyelevation.