Python访问https报错CERTIFICATE_VERIFY_FAILED

在Mac上安装Python3.6并使用urllib库访问网页时遇到ssl.SSLError错误,原因是Python3.6内置的OpenSSL未使用系统证书。解决办法是运行特定命令来安装信任证书。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Mac上安装了Python 3.6版本,使用urllib库访问网页却返回了

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)
1
这样的错误。

这是由于MacOS版本的python 3.6版本没有使用系统的openssl进行证书验证。在/Applications/Python\ 3.6/目录下可以找到Readme.rtf文件,其中说明到:

NEW This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2. Unlike previous releases, the deprecated Apple-supplied OpenSSL libraries are no longer used. This also means that the trust certificates in system and user keychains managed by the Keychain Access application and the security command line utility are no longer used as defaults by the Python ssl module.

解决方法是运行/Applications/Python\ 3.6/Install\ Certificates.command命令,安装certifi模块即可。

可见stackoverflow上的帖子:
urllib and “SSL: CERTIFICATE_VERIFY_FAILED” Error
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值