Python ssl.SSLError:证书validation失败(_ssl.c:748)

我在Python 3.6应用程序中使用[geopy][1] ,我必须在使用Windows 2012 Server的过时机器上运行它。 从应用程序调用这个库在这个服务器上,因为它返回以下错误:

 File "C:\ServAPI\Util.py", line 12, in getLocation location = geolocator.geocode(name) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\geopy\geocoders\osm.py", line 193, in geocode self._call_geocoder(url, timeout=timeout), exactly_one File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\geopy\geocoders\base.py", line 171, in _call_geocoder raise GeocoderServiceError(message) geopy.exc.GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) 

我该如何解决这个问题? 我在Windows 2012 Server上运行Python 3.6.0

UPDATE

代码是下一个:

 from geopy.geocoders import Nominatim from geopy.exc import GeocoderTimedOut def getLocation(name): geolocator = Nominatim() try: location = geolocator.geocode(name, timeout=5) return location except GeocoderTimedOut as e: print("Error: geocode failed on input %s with message %s" % (e.msg)) 

最后,我有解决方案:

win2012可能已经过时了SSL库。 所以,解决方案是明确指出schemahttp

正确的代码是:

 from geopy.geocoders import Nominatim from geopy.exc import GeocoderTimedOut def getLocation(name): geolocator = Nominatim(scheme='http') try: location = geolocator.geocode(name, timeout=5) return location except GeocoderTimedOut as e: print("Error: geocode failed on input %s with message %s" % (e.msg))