AttributeError:'module'对象没有Python 2.7.11的属性'PROTOCOL_TLSv1_2'

gpr*_*ime 8 python macos ssl openssl python-2.7

我在我的mac上获得tls v1.2支持我的python安装时遇到问题.

这是我的openssl版本:

openssl version
OpenSSL 1.0.2h  3 May 2016
Run Code Online (Sandbox Code Playgroud)

这是我的python版本:

python --version
Python 2.7.11
Run Code Online (Sandbox Code Playgroud)

这就是我测试的方式:

>>> 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'
Run Code Online (Sandbox Code Playgroud)

阅读本文:https://docs.python.org/2/library/ssl.html 它说:

某些行为可能与平台有关,因为对操作系统套接字API进行了调用.安装的OpenSSL版本也可能导致行为的变化.例如,TL​​Sv1.1和TLSv1.2附带openssl版本1.0.1.

所以我对安装OpenSSL 1.0.2h的tlsv1.2支持有要求.

有人有主意吗?

gpr*_*ime 4

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

我用brew安装了openssl,然后重新安装了python,告诉它使用我用brew安装的openssl:

$ brew update
$ brew install openssl
$ brew install python --with-brewed-openssl
Run Code Online (Sandbox Code Playgroud)

然后一切就都成功了!

  • 今天尝试这个:错误:无效选项:--with-brewed-openssl (3认同)
  • ubuntu 有类似的解决方案吗,@gprime?我有同样的问题,但在 Ubuntu 上使用 Django。 (2认同)