0

Force TLS 1.2 in Python 2.7.14

Hi I need to update my python code (version 2.7.14) which uses urllib2.open to force it to use TLS1.2 So far I have tried Sending TLS 1.2 request in Python 2.6

But I get AttributeError("'module' object has no attribute 'SSLContext'",)

 ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
 response = urllib2.urlopen(url, context=ctx).read()

The options I have SSLContext are

PROTOCOL_TLSv1
PROTOCOL_SSLv23
PROTOCOL_SSLv2
PROTOCOL_SSLv3

PROTOCOL_TLSv2 is not available

denis_lor
  • 6,212
  • 4
  • 31
  • 55
  • 1
    Friendly warning: Python 2.7 is EOL in 8 months. https://pythonclock.org/ Please consider upgrading asap. – rdas Apr 17 '19 at 11:56
  • I was really hesitant to go from 2 to 3 for a long time... but for a while now it's been a necessary transition. Particularly with the evolving SSL situation. Without more context on your project, we can't offer more useful guidance, but at this point it's almost certainly in your best interest to put in whatever time it takes to update to 3.x. – kungphu Apr 17 '19 at 12:07
  • Hi I would update to 3x, but we have a number of other scripts developed with v2.7, hence will be much effort to upgrade all. But anyway, how would v3x help with the TLS 1.2 issue? – user3050151 Apr 17 '19 at 13:03

0 Answers0