import requests
url = "http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo"
request = requests.get(url)
fetch_data = request.json()
print (request.content)
for item in fetch_data:
print(item)
I am trying to fetch items within JSON Request geonames -> lng. If I make use of item['lng']
Then getting error
TypeError: string indices must be integers
EXAMPLE of JSON Request
{
"geonames":[
{
"lng":-99.12766456604,
"geonameId":3530597,
"countrycode":"MX",
"name":"Mexiko-Stadt",
"fclName":"city, village,...",
"toponymName":"Mexico City",
"fcodeName":"capital of a political entity",
"wikipedia":"en.wikipedia.org/wiki/Mexico_City",
"lat":19.428472427036,
"fcl":"P",
"population":12294193,
"fcode":"PPLC"
}
]
}
fetch_data, soitemis the key (e.g.'geonames'), which is a string, as the error message tells you.for key, item in fetch_data.enumerate():'dict' object has no attribute 'enumerate'...?the daily limit of 30000 credits for demo has been exceeded.