gmplot: Calling `from_geocode` occasionally produces "list index out of range" error
I’ve been using gmplot to draw running routes (via tcx files). Until recently I could loop through a file list and generate the new html plots.
But now the loop will seemingly-spontaneously fail and generate the following error:
40 'http://maps.googleapis.com/maps/api/geocode/json?address="%s"' % location_string) 41 geocode = json.loads(geocode.text)—> 42 latlng_dict = geocode[‘results’][0][‘geometry’][‘location’] 43 return latlng_dict[‘lat’], latlng_dict[‘lng’] 44
IndexError: list index out of range
I was able to isolate it to the call for
gmap = gmplot.GoogleMapPlotter.from_geocode("San Francisco")
For example, running the following code will result in throwing an error at some point (usually in the 8-14 range):
for i in range(25):
print(i)
gmap = gmplot.GoogleMapPlotter.from_geocode("San Francisco")
I can wrap it in a try/except but that merely delays the break.
My naive guess is that I’m breaking some API limit.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (3 by maintainers)
fixed with:
ie you’re forced to pass and API key (as gmaps forces you to)
Fixed in #111.
Any chance this can get merged into the official release? Or do I need to fork yet another project to fix bugs that have had a solution sitting around in some other fork for a while?
the issue is pretty obvious looking at the code:
first you need to call that URL using https, second you need to pass the GMaps API key to it (or gmaps will reply back with an error saying “Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account”)