Posted on October 12, 2018 5:22 pm
 |  Asked by Albert Albert
 |  3914 views
RESOLVED
0
0
Print Friendly, PDF & Email

I wrote a Python script (version 2.7) in the past to login to an EOS switch. Now I switched to version 3.6.5 and I ran into the following SSLError: Any solution / workaround. Thanks

Attachments:
2
Posted by ASHWIN C S
Answered on October 12, 2018 5:38 pm

Hello Albert,

Could you please add the below lines of code to your code and let me know if it fixes things?

import ssl

try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn’t verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn’t support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context

Regards,
Ashwin

Thanks Ashwin

This work

(Albert Albert at October 13, 2018 12:36 am)
0
Posted by Adam Levin
Answered on October 12, 2018 5:39 pm

As of Python 2.7.9, Python now does SSL certificate verification for better security. Due to this security it’s possible older scripts might break if there are issues with the certificates.

There are a few ways to work around this.

First, you could turn off verification, but note that you probably shouldn’t do this. If you want to try, just set an environment variable PYTHONHTTPSVERIFY=0 in your shell and export it, or set it in your script.

If you’re running on an Apple OS and you installed Python 3.6 separately, you should probably have a directory /Applications/Python 3.6. If so, two options:

Run pip to install certificates: pip install –upgrade certifi
OR
Run the script that came with Python: /Applications/Python 3.6/Install Certificates.command

These will install a curated list of certificates as part of your trust ring. Python 3.6 doesn’t use Apple’s Keychain Manager application.

A third option which may work is to modify your script to use the SSL module to work around:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Let me know if you still have trouble after trying one or more of these. Good luck!

Post your Answer

You must be logged in to post an answer.