-3

When running the code below in Python 2.7.10 under Anaconda with no Conda virtual environment, it works fine. That's one year ago.

from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.reverse("16.890568, 42.543554", language="en")

Got this error if running the same code now in Anaconda Conda virtual environment in which the root is Python 3.6 and the used virtual environment is Python 2.7.

GeocoderServiceError: 
  <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)>

Tried to search SO, Google and check geopy, still found no answer. During the search, it seems that to disable ssl certificate check might be a viable solution but don't know how. Welcome for any advice.

thewaywewere
  • 8,128
  • 11
  • 41
  • 46
  • It's not recommend to disable, try [python-certifi](https://github.com/certifi/python-certifi) – stovfl Aug 20 '17 at 14:43

1 Answers1

0

Come across this site and got the workaround to make it works again. Just insert the try-except-else code before assigning the geolocator.

from geopy.geocoders import Nominatim

# Disable SSL certificate verification 
try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

location = geolocator.reverse("16.890568, 42.543554", language="en")
thewaywewere
  • 8,128
  • 11
  • 41
  • 46