running windows 10 with Python 3.10. I have been running into an SSL error when I attempt to use the Nominatim service. I do not see this error with ArcGIS service.
Example code:
import certifi
import ssl
import geopy.geocoders
from geopy.geocoders import Nominatim
from geopy.geocoders import ArcGIS
ctx = ssl.create_default_context(cafile=certifi.where())
geopy.geocoders.options.default_ssl_context = ctx
print('')
print('Trying Nominatim')
try:
geolocator_NOM = Nominatim(user_agent="NewApp314", timeout=10)
location_NOM = geolocator_NOM.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
print(f'Location Address: {location_NOM.address}')
print(f'Location Latitude: {location_NOM.latitude}')
print(f'Location Longitude: {location_NOM.longitude}')
except Exception as error:
print(f'Error in Nominatim: {error}')
print('')
print('Trying ArcGIS:')
try:
geolocator_ARC = ArcGIS()
location_ARC = geolocator_ARC.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
print(f'Location Address: {location_ARC.address}')
print(f'Location Latitude: {location_ARC.latitude}')
print(f'Location Longitude: {location_ARC.longitude}')
except Exception as error:
print(f'Error in ArcGIS: {error}')
When I run the code I receive the following output:
Trying Nominatim:
Error in Nominatim: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=1600+Amphitheatre+Parkway%2C+Mountain+View%2C+CA&format=json&limit=1 (Caused by
SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')))
Trying ArcGIS:
Location Address: 1600 Amphitheatre Pkwy, Mountain View, California, 94043
Location Latitude: 37.421976010046
Location Longitude: -122.084524027111
I've looked all over for solutions and noticed a couple similar errors on stack Overflow, but no solutions:
Geopy Nominatim SSLCertVerificationError
Similar error, but solution did not fix issue identified Python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)