美文网首页
Python 打开https链接报错:unable to get

Python 打开https链接报错:unable to get

作者: Zhen斌iOS | 来源:发表于2025-03-31 11:14 被阅读0次

Python打开https链接报错:unable to get local issuer certificate 或安装Python3.10以上版本,需要openssl 1.1.1以上版本,会导致openssl 下面缺少证书,记录下安装方法

问题描述:

当使用urllib.urlopen打开一个 https 链接时抛出如下异常:

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>

原因:

本地证书不存在。

解决方法:

1、查看默认证书位置

import ssl
print(ssl.get_default_verify_paths())

执行结果:

DefaultVerifyPaths(cafile=None, capath=None, openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/Library/Frameworks/Python.framework/Versions/3.7/etc/openssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/Library/Frameworks/Python.framework/Versions/3.7/etc/openssl/certs')

由结果可见,ca文件不存在。

2、下载ca文件

http://curl.haxx.se/ca/cacert.pem

3、将 cacert.pem 改成 cert.pem 放在证书指定目录:/Library/Frameworks/Python.framework/Versions/3.7/etc/openssl/cert.pem

相关文章

网友评论

      本文标题:Python 打开https链接报错:unable to get

      本文链接:https://www.haomeiwen.com/subject/ayfmvjtx.html