欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python访问https报错CERTIFICATE_VERIFY_FAILED 博客分类: python3  

程序员文章站 2024-03-19 17:21:22
...
在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模块即可。

可见*上的帖子:
urllib and “SSL: CERTIFICATE_VERIFY_FAILED” Error