AttributeError: 'module' 对象在 Python 2.7.11 中没有属性 'PROTOCOL_TLSv1_2' [英] AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2.7.11

查看:48
本文介绍了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 版本可能也会导致行为的变化.例如,TL​​Sv1.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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆