geocoder icon indicating copy to clipboard operation
geocoder copied to clipboard

"Too many open files" error

Open ianbstewart opened this issue 4 years ago • 1 comments

After using geocoder.osm for a few hundred queries, I get the same error over and over from geocoder:

ERROR - HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /sea
rch?q=NYC&format=jsonv2&addressdetails=1&limit=1 (Caused by SSLError(OSError(24, 'Too many open files')))

I don't think that the problem is on my end. It seems like a weird version of rate limiting. I added a sleep function for 5 seconds between queries but that didn't change anything. How to fix this error?

ianbstewart avatar May 19 '21 05:05 ianbstewart

I was investigating a different warning, but I think the root cause is the same: Geocoder does not explicitly close the HTTP session it makes use of: https://github.com/DenisCarriere/geocoder/blob/39b9999ec70e61da9fa52fe9fe82a261ad70fa8b/geocoder/base.py#L389 It is by design, since it can reuse a session created elsewhere. Even though I would expect it to close itself the session it creates on its own or at least clearly document this in the docs (the section “Using a Session” has no mention of the fact that Geocoder will create a session if one is not provided in the kwargs).

The solution is to explicitly close the session after you’ve retrieved the results:

    result = geocoder.osm( ... )
    result.session.close()

interDist avatar Aug 30 '22 08:08 interDist