Forum Discussion
mishpan_70054
Jan 27, 2015Nimbostratus
issue while using -pyControl with python2.7 (SSL: CERTIFICATE_VERIFY_FAILED)
While using python2.7 with pyControl, i am getting below error. After googling i have found that in python2.7 when script try to connect to LB it's try to verifiy the certifcate lb preseting and tha...
John_Gruber_432
Historic F5 Account
Let's try that again.. I'll stop fighting Dev Central and use an 'acceptable browser'... Here is the code example to runtime patch suds:
import urllib2
import ssl
from suds import transport
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
from pycontrol import pycontrol
IMP = Import('[http://schemas.xmlsoap.org/soap/encoding/](http://schemas.xmlsoap.org/soap/encoding/)')
DOCTOR = ImportDoctor(IMP)
ICONTROL_URI = '/iControl/iControlPortal.cgi'
SESSION_WSDL = 'System.Session'
class HTTPSUnVerifiedCertTransport(transport.https.HttpAuthenticated):
def __init__(self, *args, **kwargs):
transport.https.HttpAuthenticated.__init__(self, *args, **kwargs)
def u2handlers(self):
handlers = []
handlers.append(urllib2.ProxyHandler(self.proxy))
handlers.append(urllib2.HTTPBasicAuthHandler(self.pm))
python ssl Context support - PEP 0466
if hasattr(ssl, '_create_unverified_context'):
ssl_context = ssl._create_unverified_context()
handlers.append(urllib2.HTTPSHandler(context=ssl_context))
else:
handlers.append(urllib2.HTTPSHandler())
return handlers
def new_get_suds_client(self, url, **kw):
if not url.startswith("https"):
t = transport.http.HttpAuthenticated(username=self.username,
password=self.password)
c = Client(url, transport=t, username=self.username,
password=self.password, doctor=DOCTOR, **kw)
else:
t = HTTPSUnVerifiedCertTransport(username=self.username,
password=self.password)
c = Client(url, transport=t, username=self.username,
password=self.password, doctor=DOCTOR, **kw)
return c
pycontrol.BIGIP._get_suds_client = new_get_suds_client
device = pycontrol.BIGIP(hostname='192.168.245.1', username='admin', password='admin', fromurl=True, wsdls=['LocalLB.Pool'])
tjsauter_208299
Jun 30, 2015Nimbostratus
Excellent! Exactly what I needed, thanks for posting
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects