I'm trying to get a country name by lat lon (reverse encoding) using Python. I got to Nominatim with GeoPy which worked great two times but now I keep getting Max retries exceeded error.
My code:
from geopy.geocoders import Nominatim
def get_countries(lat,lon):
coordinates = f'{lat} {lon}'
locator = Nominatim(user_agent='myencoder', timeout=10)
location = locator.reverse(coordinates,language='en')
country = location.raw['address']['country_code'].upper()
return [country,lat,lon]
get_countries(32.782023,35.478867)
In practice I would like to use this function for about 100-200 locations, but I get the error also for this one location. It worked the first time I run the code, but then I'm keep getting:
GeocoderUnavailable: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /reverse?lat=32.782023&lon=35.478867&format=json&accept-language=en&addressdetails=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F7AA229978>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
I've tried changing the user_agent
by writing my email or another name as suggested here, I also read the answers here and here, also other solutions. All resulted in this error.
What else can I do? Are there other reliable options using Python to get a country name (preferably with to letters e.g., ES, IT, US, etc.) by lat lon?