Python 打開https鏈接報(bào)錯(cuò):unable to get local issuer certificate

Python打開https鏈接報(bào)錯(cuò):unable to get local issuer certificate 或安裝Python3.10以上版本,需要openssl 1.1.1以上版本,會導(dǎo)致openssl 下面缺少證書,記錄下安裝方法

問題描述:

當(dāng)使用urllib.urlopen打開一個(gè) https 鏈接時(shí)拋出如下異常:

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

原因:

本地證書不存在。

解決方法:

1、查看默認(rèn)證書位置

import ssl
print(ssl.get_default_verify_paths())

執(zhí)行結(jié)果:

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')

由結(jié)果可見,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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容