From dccb1c3375c4369989845762073f296c78855ede Mon Sep 17 00:00:00 2001 From: Stacy Brock Date: Thu, 30 Jan 2014 14:29:57 -0800 Subject: [PATCH 1/3] Fix SSL error when connecting from behind a proxy In certain versions of python, urllib fails when making https requests from behind a proxy. See http://bugs.python.org/issue1424152 for details. This patch fixes an issue with pyVim by using urllib2 instead of urllib, a change similar to existing code (see OpenUrlWithBasicAuth() and OpenPathWithStub()). --- pyVim/connect.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyVim/connect.py b/pyVim/connect.py index c6b3499..b39c27d 100644 --- a/pyVim/connect.py +++ b/pyVim/connect.py @@ -427,9 +427,11 @@ def __GetServiceVersionDescription(protocol, server, port, path): tree = ElementTree() + import urllib2 + url = "%s://%s:%s/%s/vimServiceVersions.xml" % (protocol, server, port, path) try: - with closing(urllib.urlopen(url)) as sock: + with closing(urllib2.urlopen(url)) as sock: if sock.getcode() == 200: tree.parse(sock) return tree @@ -438,7 +440,7 @@ def __GetServiceVersionDescription(protocol, server, port, path): url = "%s://%s:%s/%s/vimService.wsdl" % (protocol, server, port, path) try: - with closing(urllib.urlopen(url)) as sock: + with closing(urllib2.urlopen(url)) as sock: if sock.getcode() == 200: tree.parse(sock) return tree From 961e8ae0c61a29fe64d248d5b2a92cc0d8f950b1 Mon Sep 17 00:00:00 2001 From: Stacy Brock Date: Thu, 30 Jan 2014 14:29:57 -0800 Subject: [PATCH 2/3] Fix SSL error when connecting from behind a proxy In certain versions of python, urllib fails when making https requests from behind a proxy. See http://bugs.python.org/issue1424152 for details. This patch fixes an issue with pyVim by using urllib2 instead of urllib, a change similar to existing code (see OpenUrlWithBasicAuth() and OpenPathWithStub()). --- pyVim/connect.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyVim/connect.py b/pyVim/connect.py index c6b3499..4ba2a19 100644 --- a/pyVim/connect.py +++ b/pyVim/connect.py @@ -41,7 +41,7 @@ try: except ImportError: from elementtree.ElementTree import ElementTree from xml.parsers.expat import ExpatError -import urllib +import urllib2 """ @@ -429,7 +429,7 @@ def __GetServiceVersionDescription(protocol, server, port, path): url = "%s://%s:%s/%s/vimServiceVersions.xml" % (protocol, server, port, path) try: - with closing(urllib.urlopen(url)) as sock: + with closing(urllib2.urlopen(url)) as sock: if sock.getcode() == 200: tree.parse(sock) return tree @@ -438,7 +438,7 @@ def __GetServiceVersionDescription(protocol, server, port, path): url = "%s://%s:%s/%s/vimService.wsdl" % (protocol, server, port, path) try: - with closing(urllib.urlopen(url)) as sock: + with closing(urllib2.urlopen(url)) as sock: if sock.getcode() == 200: tree.parse(sock) return tree @@ -593,7 +593,6 @@ def OpenUrlWithBasicAuth(url, user='root', pwd=''): the specified credentials to the server as part of the request. Returns the response as a file-like object. """ - import urllib2 pwMgr = urllib2.HTTPPasswordMgrWithDefaultRealm() pwMgr.add_password(None, url, user, pwd) handler = urllib2.HTTPBasicAuthHandler(pwMgr) @@ -608,7 +607,6 @@ def OpenPathWithStub(path, stub): file-like object. """ import httplib - import urllib2 if not hasattr(stub, 'scheme'): raise vmodl.fault.NotSupported() elif stub.scheme == httplib.HTTPConnection: From cae89d4cf6c575662cdd5d7f1b55b3ffb2034d48 Mon Sep 17 00:00:00 2001 From: Stacy Brock Date: Mon, 17 Feb 2014 14:24:17 -0800 Subject: [PATCH 3/3] Remove unneeded import --- pyVim/connect.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyVim/connect.py b/pyVim/connect.py index 313a16c..4ba2a19 100644 --- a/pyVim/connect.py +++ b/pyVim/connect.py @@ -427,8 +427,6 @@ def __GetServiceVersionDescription(protocol, server, port, path): tree = ElementTree() - import urllib2 - url = "%s://%s:%s/%s/vimServiceVersions.xml" % (protocol, server, port, path) try: with closing(urllib2.urlopen(url)) as sock: