3

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?

Waqar Ahmed
  • 1,414
  • 2
  • 15
  • 35
  • Which SSL library are you using? – Simon Fraser Jun 16 '16 at 07:30
  • @SimonFraser I am sorry, how do I check it? I don't understand your question. – Waqar Ahmed Jun 16 '16 at 07:31
  • What are you doing to get TLSv1 support? Did you install the "pyopenssl" module, have `import ssl` in your code, or something else? – Simon Fraser Jun 16 '16 at 07:34
  • @SimonFraser Well I have not used `import ssl` explicitly or installed "pyopenssl". For communication (request/response) I am using `requests 2.9.1` library – Waqar Ahmed Jun 16 '16 at 07:38
  • I think this is the answer you're after, then: http://stackoverflow.com/a/29155638/3527520, with the `SSLContext` and the link to the requests documentation at the bottom for how to use it – Simon Fraser Jun 16 '16 at 07:41
  • @SimonFraser does this means that I have to upgrade my python version? Isn't there any out of the way solution? – Waqar Ahmed Jun 17 '16 at 06:32
  • @WaqarAhmed I'm afraid you'll have to upgrade your python version. Not that it is a bad thing. Upgrading to Python 2.7.9 or later should work fine. – Quirk Jun 17 '16 at 07:06

1 Answers1

4

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()
Richard Urban
  • 339
  • 3
  • 7