import urllib.request
import json
gojson = 'https://nominatim.openstreetmap.org/details.php?osmtype=W&osmid=17025436&class=highway&addressdetails=1&hierarchy=0&group_hierarchy=1&format=json&polygon_geojson=1'
res_body = urllib.request.urlopen(gojson).read()
错误:
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)>
我知道我可以使用以下代码来解决该错误:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
但我更想知道如何解决这个问题。我在网上搜索时无法找到解决方案。有什么建议吗?
最佳答案
如果您使用的是 Ubuntu 计算机,则:
sudo apt install ca-certificates
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs
如果您使用的是Mac或者需要以其他方式处理,请引用以下答案:
关于python - 如何解决[SSL : CERTIFICATE_VERIFY_FAILED] Error when Using urllib without bypassing SSL verification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69692910/