This works for python 2.7 as well.
In my scenario i have netapps using TLS or SSLv3, so i created a seperate NaServer.py which specified SSLv3 instead:
connection = httplib.HTTPSConnection(server, port=self.port, timeout=self.timeout, context=ssl.SSLContext(ssl.PROTOCOL_SSLv3))
Then in my phython script i import both as such:
from NaServer import *
import NaServer_SSL3
Then just have a simple boolean variable that i set to use the other library:
def na_setup(netapp, sslv3=False):
if sslv3:
ss = NaServer_SSL3.NaServer(netapp, 1, 1)
else:
ss = NaServer(netapp, 1, 1)
return ss
I tried monkey patching ssl._create_default_https_context a few times, but as my script makes a tong of other api calls, this was a bit outside my python comfort zone.
Also worth mentioning that i battled weak ciphers with older 7mode systems for a few days and finally found a combination that worked for all my netapps:
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
ssl._DEFAULT_CIPHERS += ':RC4-SHA'
Thanks!
You got me on the right path.
Matt S.