23
In [1]: import ssl

In [2]: context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

AttributeError  Traceback (most recent call last)
<ipython-input-2-13c9bad66150> in <module>()
----> 1 context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

AttributeError: 'module' object has no attribute 'SSLContext'

Python version: 2.7.6

2 Answers 2

40

SSLContext was introduced in 2.7.9, you're using an old version of Python so it doesn't have this attribute.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer ! Is there any workaround for python 2.7.6 ?
Nope, install the latest version.
I actually tried in python 2.7.10 and still got the AtributeError. Updating to 2.7.11 solved it, I'm still not sure why, but this might help someone else.
0

You can use code below for Python 2.7.9:

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode=ssl.CERT_NONE

2 Comments

Plz remove ";" and press enter key. Sorry had to add ";" at the end of line because SO was generating error that code can only be posted by selecting code block and inserting 4 spaces. But on mobile there isn't any option available or displaying code block.
2.7.6 does not have create_default_context

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.