Commit 2e32d86f authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Restore compatibility with Python 2.6 in HTTPS cls

Fixes grnet/kamaki#73

The problem is caused by the argument "source_address' when
instantiating "httplib.HTTPSConnection" in "kamaki.clients.utils.https"
This argument was added in Python 2.7, therefore a TypeError would
ensue with Python 2.6
This is fixed by catching the TypeError and retrying without the
"source_address" argument.
parent 07774038
......@@ -16,6 +16,8 @@ Bug fixes
* Set a default logger to LoggedAstakosClient [grnet/kamaki#58]
* Show the correct name when switching kamaki users
* Fix Python 2.6 compatibility concerning with HTTPS arguments
......@@ -45,34 +45,16 @@ class HTTPSClientAuthConnection(httplib.HTTPSConnection):
ca_file, raise_ssl_error = None, True
def __init__(
self, host,
kwargs = dict()
if port is not None:
kwargs['port'] = port
if key_file is not None:
kwargs['key_file'] = key_file
if port is not None:
kwargs['cert_file'] = cert_file
if key_file is not None:
kwargs['key_file'] = key_file
if timeout is not None:
kwargs['timeout'] = timeout
if source_address is not None:
kwargs['source_address'] = source_address
httplib.HTTPSConnection.__init__(self, host, **kwargs)
self.ca_file = ca_file or getattr(self, 'ca_file')
self.raise_ssl_error = raise_ssl_error if (
raise_ssl_error is not None) else getattr(self, 'raise_ssl_error')
def __init__(self, *args, **kwargs):
""" Extent HTTPSConnection to support SSL authentication
:param ca_file: path to CA certificates bundle (default: None)
:param raise_ssl_error: flag (default: True)
self.ca_file = kwargs.pop('ca_file', self.ca_file)
self.raise_ssl_error = kwargs.pop(
'raise_ssl_error', self.raise_ssl_error)
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
def connect(self):
"""Connect to a host on a given (SSL) port.
......@@ -83,8 +65,10 @@ class HTTPSClientAuthConnection(httplib.HTTPSConnection):
ssl.wrap_socket(), which forces SSL to check server certificate against
our client certificate.
sock = socket.create_connection(
(, self.port), self.timeout, self.source_address)
source_address = getattr(self, 'source_address', None)
socket_args = [(, self.port), self.timeout] + (
[source_address, ] if source_address else [])
sock = socket.create_connection(*socket_args)
if self._tunnel_host:
self.sock = sock
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment