I am using geopy to geocode some addresses and I want to catch the timeout errors and print them out so I can do some quality control on the input. I am putting the geocode
Try this:
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderTimedOut
my_address = '1600 Pennsylvania Avenue NW Washington, DC 20500'
geolocator = Nominatim()
try:
location = geolocator.geocode(my_address)
print(location.latitude, location.longitude)
except GeocoderTimedOut as e:
print("Error: geocode failed on input %s with message %s"%(my_address, e.message))
You can also consider increasing the timeout on the geocode call you are making to your geolocator. In my example it would be something like:
location = geolocator.geocode(my_address, timeout=10)
or
location = geolocator.geocode(my_address, timeout=None)