Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to support TLS 1.1, 1.2 for Python (2.7)

Tags:

python

tls1.2

I have developed an application in Python 2.7. But it only supports PROTOCOL_TLSv1. I have to somehow make it compatible with PROTOCOL_TLSv1_1 and PROTOCOL_TLSv1_2. I can't find any library or trick to do so. Is it necessary to upgrade the Python version?

Kindly guide me or help me find the better solution. Isn't there any out of the way solution?

like image 442
Waqar Ahmed Avatar asked Dec 04 '25 17:12

Waqar Ahmed


1 Answers

libopenssl1 and python 2.7.9 provided you can force ssl.SSLContext like :

import ssl, urllib2
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
response = urllib2.urlopen(url, context=ctx).read()
like image 93
Richard Urban Avatar answered Dec 07 '25 14:12

Richard Urban



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!