Python访问https报错CERTIFICATE_VERIFY_FAILED

来源:互联网 发布:开淘宝店名字 编辑:程序博客网 时间:2024/05/22 04:33

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

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)

这样的错误。

这是由于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

阅读全文
0 0
原创粉丝点击