python - 属性错误 : 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2. 7.11

标签 python macos python-2.7 ssl openssl

我在为 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。

有人有什么想法吗?

最佳答案

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

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

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

然后一切正常!

关于python - 属性错误 : 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2. 7.11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37304907/

相关文章:

python - Linux下如何用Python创建master进程?

python - Cython:numpy 数组的无符号整数索引给出不同的结果

ios - 在 SwiftUI 中,是否可以仅对某个 os 目标使用修饰符?

python - 我的Python猜数字游戏的问题

python - smart_unicode 在我的 Django 项目中不起作用

python - 无法使用 PyPi 正确发布模块

macos - 核心数据迁移机制是否会处理预填充实体上的新数据?

macos - Mac OS X 上的 node.js npm "Error: No such module"

python - 替换周围已知但字符串值未知的字符串 Python

python - 如何从python中的mkv文件读取视频图像?