Skip to content

Instantly share code, notes, and snippets.

@jcarlosroldan
Last active July 24, 2018 11:40
Show Gist options
  • Save jcarlosroldan/ed5926a84e980922bea5b6a0e4380744 to your computer and use it in GitHub Desktop.
Save jcarlosroldan/ed5926a84e980922bea5b6a0e4380744 to your computer and use it in GitHub Desktop.
Geocode a place and retry everytime it fails
from geopy.exc import GeocoderTimedOut
from geopy.geocoders import Nominatim
# Choose your preferred geocoder at http://geopy.readthedocs.io/en/latest/#module-geopy.geocoders
_geo = Nominatim()
def where(place, timeout=10):
res = None
while res == None:
try:
res = _geo.geocode(place, timeout=timeout)
except GeocoderTimedOut:
print("Geocoding failed for %s. Retrying..." % place)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment