我在一个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
更新
代码如下:
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))
发布于 2017-11-03 16:54:10
最后,我有了解决方案:
可能是win2012
的SSL
库已过期。因此,解决方案是显式地指出schema
是http
正确的代码是:
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))
发布于 2018-06-03 18:41:59
我也有同样的问题,但最终不得不安装SSL和Certifi。我不确定其他人是否会有这个问题,但如果是的话,下面是我是如何解决这个问题的。
首先安装Certifi和SSL包,然后
import certifi
import ssl
import geopy.geocoders
from geopy.geocoders import Nominatim
ctx = ssl.create_default_context(cafile=certifi.where())
geopy.geocoders.options.default_ssl_context = ctx
geolocator = Nominatim(scheme='http')
location = geolocator.reverse("48.8588443, 2.2943506")
print(location.address)
print (location.raw)
然后,结果是:
Tour Eiffel, 5, Avenue Anatole France, Gros-Caillou, 7e, Paris, Île-de-France, France métropolitaine, 75007, France
{'place_id': '62005962', 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': '5013364', 'lat': '48.8582602', 'lon': '2.29449905431968', 'display_name': 'Tour Eiffel, 5, Avenue Anatole France, Gros-Caillou, 7e, Paris, Île-de-France, France métropolitaine, 75007, France', 'address': {'attraction': 'Tour Eiffel', 'house_number': '5', 'pedestrian': 'Avenue Anatole France', 'suburb': 'Gros-Caillou', 'city_district': '7e', 'city': 'Paris', 'county': 'Paris', 'state': 'Île-de-France', 'country': 'France', 'postcode': '75007', 'country_code': 'fr'}, 'boundingbox': ['48.8574753', '48.8590465', '2.2933084', '2.2956897']}
发布于 2021-10-08 07:46:25
对于最近遇到这个问题的人,这是我在2021年的测试结果:在我的环境中,python 3.6.8 + geopy 2.2.0 + centos 7可以工作;python 2.7.18 + geopy 1.23.0 + centos 8也可以;但python 2.7.5 + geopy 1.23.0 + centos 7不能工作并报告证书错误。
最后,我找到了根本原因,它是由于9月9日到期的原因。LetsEncrypt使用的旧'DST‘根证书的30;请参阅https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021。如果Python使用低于1.1.0的OpenSSL,则会受到影响;请参阅https://openssl.org/blog/blog/2021/09/13/LetsEncryptRootCertExpire。
我使用了python 2.7.5 + geopy 1.23.0 + centos 7+ openssl 1.0.2k-fips,解决方法1是从系统证书中删除(DST Root CA X3)根证书,详细步骤如下:
/etc/pki/tls/certs/ca-bundle.crt
中,ISRG根目录X1也在中。/etc/pki/ca-trust/source/blacklist
目录中作为pem文件/etc/pki/tls/certs/ca-bundle.crt
中,ISRG根目录X1在ISRG根目录X1中。<代码>H214<代码>G215参考:
更新:正如@rsc所指出的,更新您的ca证书也可能起作用:
yum upgrade ca-certificates
https://stackoverflow.com/questions/46560143
复制相似问题