From a8136c5d3bf2c206142c83d2c0c09d59da9c81ad Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 28 Mar 2016 03:32:38 +0200 Subject: [PATCH 1/2] add support for Basic HTTP authentication to _http_request --- wcs/qommon/misc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wcs/qommon/misc.py b/wcs/qommon/misc.py index 0776d63..20ea565 100644 --- a/wcs/qommon/misc.py +++ b/wcs/qommon/misc.py @@ -241,6 +241,15 @@ def _http_request(url, method='GET', body=None, headers={}, timeout=None): else: hostname, query = urllib.splithost(url[6:]) + if '@' in hostname: + authenticator, hostname = hostname.split('@') + if ':' in authenticator: + username, password = authenticator.split(':', 1) + else: + username = authenticator + password = '' + headers['Authorization'] = 'Basic %s' % base64.b64encode('%s:%s' % (username, password)) + if url.startswith('http://'): if timeout is None: conn = httplib.HTTPConnection(hostname) -- 2.1.4