AttributeError: #39;module#39; object has no attribute #39;PROTOCOL_TLSv1_2#39; with Python 2.7.11(AttributeError: module 对象在 Python 2.7.11 中没有属性 PROTOCOL_TLSv1_2)
问题描述
我在为 Mac 上的 python 安装获取 tls v1.2 支持时遇到问题.
这是我的 openssl 版本:
openssl 版本OpenSSL 1.0.2h 2016 年 5 月 3 日这是我的python版本:
python --version蟒蛇 2.7.11
这是我的测试方式:
<预><代码>>>>导入 ssl>>>ssl.PROTOCOL_TLSv1_2回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中AttributeError: 'module' 对象没有属性 'PROTOCOL_TLSv1_2'
阅读:https://docs.python.org/2/library/ssl.html它说:
<块引用>某些行为可能取决于平台,因为调用是对操作系统套接字 API.已安装的 OpenSSL 版本可能也会导致行为的变化.例如,TLSv1.1 和 TLSv1.2附带 openssl 版本 1.0.1.
所以我的 OpenSSL 1.0.2h 安装要求支持 tlsv1.2.
有人有什么想法吗?
问题是python使用的openssl版本不支持TLS 1.2.
我用 brew 安装了 openssl,然后重新安装了 python,告诉它使用我用 brew 安装的 openssl:
$ brew 更新$ brew install openssl$ brew install python --with-brewed-openssl
然后一切正常!
I am having issues getting tls v1.2 support for my python installation on my mac.
This is my openssl version:
openssl version
OpenSSL 1.0.2h 3 May 2016
And here is my python version:
python --version
Python 2.7.11
This is how I am testing:
>>> 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'
Reading this: https://docs.python.org/2/library/ssl.html It says:
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.
So I have the requirements for tlsv1.2 support with my installation of OpenSSL 1.0.2h.
Anyone have any ideas?
The problem was that the openssl version python was using did not support TLS 1.2.
I installed openssl with brew and then reinstalled python telling it to use the openssl i installed with brew:
$ brew update
$ brew install openssl
$ brew install python --with-brewed-openssl
Then everything worked!
这篇关于AttributeError: 'module' 对象在 Python 2.7.11 中没有属性 'PROTOCOL_TLSv1_2'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AttributeError: 'module' 对象在 Python 2.7.11 中没


基础教程推荐
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01