gpt4 book ai didi

python - SSL:在 Python 3.8 上运行时的 CERTIFICATE_VERIFY_FAILED。适用于其他版本的python

转载 作者:行者123 更新时间:2023-12-04 22:39:24 24 4
gpt4 key购买 nike

我在 macos 上使用 Python 3.8。我在这台机器上也有 Python 3.5 和 2.7。
我正在尝试使用以下代码段连接到 adwords.google.com:

import ssl, socket
context = ssl.create_default_context()
conn = context.wrap_socket(
socket.socket(socket.AF_INET),
server_hostname="adwords.google.com"
)
conn.connect(("adwords.google.com", 443))
cert = conn.getpeercert()
但我总是收到以下错误:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
运行 ssl.OPENSSL_VERSION 我收到:
'OpenSSL 1.1.1g  21 Apr 2020'
奇怪的是,如果我在 Python 3.5 或 Python 2.7 上运行相同的 ssl 连接片段,则连接有效。这只发生在 Python 3.8 上。
为什么会这样?有任何想法吗?

最佳答案

我找到了答案 this article还有这个问题:Django 1.11: Python 3.6 Upgrade causes issues with SSL connections .
从 Python 3.6 开始,[...] 已弃用的 Apple 提供的 OpenSSL 库不再使用。这也意味着由 Keychain Access 应用程序和安全命令行实用程序管理的系统和用户钥匙串(keychain)中的信任证书不再被 Python ssl 模块用作默认值。对于 3.6.0,/Applications/Python 3.6 中包含一个示例命令脚本,用于从第三方 certifi 包 (https://pypi.python.org/pypi/certifi) [...]
所以,我只运行了 sh/Applications/Python\3.8/Install\Certificates.command,certifi 已正确安装,并且 ssl 连接也正常工作。

关于python - SSL:在 Python 3.8 上运行时的 CERTIFICATE_VERIFY_FAILED。适用于其他版本的python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63801481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com