Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

macos - AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2.7.11

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...