6

Trying to use ssl.PROTOCOL_TLSv1_2 to make TLS1.2 HTTPS requests using Python 2.X.

It was suggested in this thread (Sending TLS 1.2 request in Python 2.6) that I need to switch from Python 2.7.6 to 2.7.10, which I did, and then utilize the ssl library.

Unfortunately, after switching to Python 2.7.10, I was unable to access ssl.PROTOCOL_TLSv1_2 (apparently I can't post images).

I'm fairly sure I'm using Python 2.7.10 because when I activate my virtual environment and call Python from the command line I see:

Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information.

I thought maybe that the issue was that the ssl library was out of date, and this is what I saw when I tried to pip install ssl --upgrade

Collecting ssl Using cached ssl-1.16.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 20, in <module> File "/private/var/folders/xl/nl55_c357zd2gqs09wfwytvh0000gn/T/pip-build-tn97bV/ssl/setup.py", line 12, in <module> + "or earlier.") ValueError: This extension should not be used with Python 2.6 or later (already built in), and has not been tested with Python 2.3.4 or earlier.

Community
  • 1
  • 1
Jae Bradley
  • 219
  • 3
  • 7
  • [Updating openssl in python 2.7](http://stackoverflow.com/q/18752409), [How to use macport to install software?](http://superuser.com/q/377727), [How to upgrade OpenSSL in OS X?](http://apple.stackexchange.com/q/126830), etc... – jww Mar 11 '16 at 21:23

2 Answers2

1

Faced the same issue. Try replacing with ssl.PROTOCOL_TLSv1.

Also make sure your SSL version is >= 1.0.1 .

It worked for me .

rose
  • 162
  • 1
  • 1
  • 13
  • I have a same problem but I already have openSSL 1.1.1 version, https://stackoverflow.com/questions/69343740/python-tls-version-matching how cna I solve my problem with your method? – gogogo Sep 27 '21 at 12:04
0

I was using python2.7.10. I changed my env to python2.7.13 which uses latest version of ssl which resolved the issue. Thanks.

gotit
  • 667
  • 6
  • 4
  • It's not working and not at all recommended to use python 2.7.x so it's better to upgrade the python version to latest and try using the TLSv1_1/TLSv1_2. – Anshuman Pattnaik Nov 19 '20 at 05:31