3

How to avoid the "GeocoderTimedOut('Service timed out')" error in geopy using the osm nominatim geocoder? I am not interested in using an exception and skip some entries. I already use a time delay of 1.1 seconds in my script using time.sleep(1.1). Total database is 10,000 entries.

http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy

  • Eventually I used the script with a 1 second delay. It took a while but the results are good. – RutgerH Dec 15 '15 at 23:41
5

You could make a recursive function. Just typing Python-esque pseudo-code:

from geopy.exc import GeocoderTimedOut

def do_geocode(address):
    try:
        return geopy.geocode(address)
    except GeocoderTimedOut:
        return do_geocode(address)

Documentation for geopy.exc.GeocoderTimedOut.

This will keep retrying the do_geocode function until it manages to return without a Timeout exception being raised. You might want to limit the number of attempts, or also set a waiting period after a failed attempt. You might also want to think about why a timeout is occurring. Geopy allows you to set the length of time to wait before raising a timeout error, for any of the geocoding methods, with the timeout keyword argument. The documentation says that "some services are consistently slow", and recommends that this be increased.

  • thanks. this was indeed part of the solution. Make sure to import: from geopy.exc import GeocoderTimedOut – RutgerH Mar 11 '16 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.