【问题标题】:AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2.7.11AttributeError:“模块”对象在 Python 2.7.11 中没有属性“PROTOCOL_TLSv1_2”
【发布时间】:2016-09-15 06:03:54
【问题描述】:

我在为我的 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 它说:

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

所以我在安装 OpenSSL 1.0.2h 时需要支持 tlsv1.2。

有人有什么想法吗?

【问题讨论】:

  • 请检查您不仅安装了新版本的openssl,而且您确实在python中使用它,即import ssl\nprint ssl.OPENSSL_VERSION
  • 是的,这就是问题所在。我重新安装了“brew install python --with-brewed-openssl”。
  • gprime,你能把它写成答案吗?

标签: python macos python-2.7 ssl openssl


【解决方案1】:

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

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

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

然后一切正常!

【讨论】:

  • 有没有安装最新 Python 的解决方案?
  • 对不起,我不知道。
  • 对于 ubuntu,@gprime 有类似的解决方案吗?我有同样的问题,但在 Ubuntu 上使用 Django。
  • 今天试试这个:错误:无效选项:--with-brewed-openssl
  • 无论这些天怎么看,基本上都是“已经使用酿造的 openssl”(尽管是特定版本,请brew edit python 看看哪个)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
  • 2013-07-05
  • 2011-10-25
  • 2017-09-02
  • 2014-07-24
  • 2015-11-21
  • 1970-01-01
相关资源
最近更新 更多