AttributeError:“module”对象没有Python 2.7.11的“PROTOCOL\u TLSv1\u 2”属性

2024-05-13 10:35:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在mac上安装python时,我无法获得tls v1.2支持。

这是我的openssl版本:

openssl version
OpenSSL 1.0.2h  3 May 2016

下面是我的python版本:

python --version
Python 2.7.11

我就是这样测试的:

>>> import ssl
>>> ssl.PROTOCOL_TLSv1_2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'

正在阅读:https://docs.python.org/2/library/ssl.html 上面写着:

Some behavior may be platform dependent, since calls are made to the operating system socket APIs. The installed version of OpenSSL may also cause variations in behavior. For example, TLSv1.1 and TLSv1.2 come with openssl version 1.0.1.

因此,我在安装OpenSSL 1.0.2h时需要tlsv1.2支持

有人有什么想法吗?


Tags: inimport版本sslversionmactlsprotocol
1条回答
网友
1楼 · 发布于 2024-05-13 10:35:50

问题是python使用的openssl版本不支持TLS 1.2。

我在brew中安装了openssl,然后重新安装了python,告诉它使用与brew一起安装的openssl:

$ brew update
$ brew install openssl
$ brew install python --with-brewed-openssl

然后一切都成功了!

相关问题 更多 >