Jas
Jas

Reputation: 15093

How to ignore certificate in python 2.6?

In Python 2.7, I can do the below and it works:

ctx = ssl.create_default_context() // function does not exist in python 2.6 ?   What to use?
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
req =  urllib2.Request('https://myurl/')

The error I'm getting:

    ctx = ssl.create_default_context()
AttributeError: 'module' object has no attribute 'create_default_context'

How can I achieve the same effect in Python 2.6 as the function create_default_context does not exist there?

Upvotes: 4

Views: 8649

Answers (1)

Daniel
Daniel

Reputation: 917

I don't have 2.6 install to test it, but I assume using the SSLContext constructor directly will work:

import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE
context.check_hostname = False

req =  urllib2.urlopen('https://myurl/', context=context)

Upvotes: 4

Related Questions