我尝试使用 Nominatim 进行地理编码,但出现 SSL 错误:
[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:证书链中的自签名证书(_ssl.c:1129)
我在 jupyter 笔记本中运行这段代码后发生错误:
nom.geocode("3995 23rd St, San Francisco, CA 94114")
我以前遇到过 SSL 错误,但它们仅在我在没有受信任主机的情况下运行 pip install 时出现。
我的操作系统是 Windows,我正在 anaconda 的 Jupyter 笔记本中运行我的代码。我使用的是 Python 3.9.13。
我想这个错误一定是因为我使用的是 anaconda。
下面是我的 Jupyer Notebook 中的所有代码块:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org geopy
from geopy.geocoders import Nominatim
nom=Nominatim(user_agent="test")
nom.geocode("3995 23rd St, San Francisco, CA 94114")
我从最后一个卡盘中收到错误。
如果这个问题很明显,我很抱歉,但我还没有找到解决方案。
我遇到了同样的错误。我正在 Visual Studio 中运行代码,Python 3.10
这是代码:
import ssl
import certifi
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= 'https', user_agent="Test Agent 314159")
location = geolocator.geocode("175 5th Avenue NYC")
这是我收到的错误:
Message=HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443):
Max retries exceeded with url: /search?
q=175+5th+Avenue+NYC&format=json&limit=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')))
Source=C:\Users\repos\School Information\School_Information.py
StackTrace:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)
During handling of the above exception, another exception occurred:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=175+5th+Avenue+NYC&format=json&limit=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
requests.exceptions.SSLError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=175+5th+Avenue+NYC&format=json&limit=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
File "C:\Users\repos\School Information\School_Information.py", line 21, in <module> (Current frame)
location = geolocator.geocode("175 5th Avenue NYC")
geopy.exc.GeocoderUnavailable: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=175+5th+Avenue+NYC&format=json&limit=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)')))