Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SSL:CERTIFICATE\u VERIFY\u在Python 3.8上运行时失败。适用于其他版本的python_Python_Ssl_Openssl - Fatal编程技术网

SSL:CERTIFICATE\u VERIFY\u在Python 3.8上运行时失败。适用于其他版本的python

SSL:CERTIFICATE\u VERIFY\u在Python 3.8上运行时失败。适用于其他版本的python,python,ssl,openssl,Python,Ssl,Openssl,我正在macos上使用Python3.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&qu

我正在macos上使用Python3.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\u版本,我收到:

'OpenSSL 1.1.1g  21 Apr 2020'
奇怪的是,如果我在Python3.5或Python2.7上运行相同的ssl连接片段,连接就会正常工作。这仅在Python3.8上发生

为什么会这样?有什么想法吗?

我在阅读中找到了答案,这个问题是这样的:

自从Python 3.6以来,[…]不再使用不推荐的Apple提供的OpenSSL库。这也意味着由Keychain访问应用程序和安全命令行实用程序管理的系统和用户密钥链中的信任证书不再被Python ssl模块用作默认值。对于3.6.0,在/Applications/Python 3.6中包含了一个示例命令脚本,用于从第三方certifi包()[…]安装一个经过管理的默认根证书包


因此,我刚刚运行了sh/Applications/Python\3.8/Install\Certificates.command,certifi安装正确,ssl连接也正常工作。

每个Python都有自己的信任存储。在某些情况下,CA在这里,而在另一些情况下则不在。