From 774158f2ec29b28e5364c3e07c69f7d26134e870 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 17 Jun 2013 04:10:29 +0000 Subject: [PATCH] utils/web.py: Fix compatibility with Python 3. --- src/utils/web.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/web.py b/src/utils/web.py index b51da9679..51326f8c7 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -117,8 +117,13 @@ def getUrlFd(url, headers=None, data=None): url = scheme + '://' + url request = urllib2.Request(url, headers=headers, data=data) if 'auth' in locals(): + if sys.version_info[0] >= 3 and isinstance(auth, str): + auth = auth.encode() + auth = base64.b64encode(auth) + if sys.version_info[0] >= 3: + auth = auth.decode() request.add_header('Authorization', - 'Basic ' + base64.b64encode(auth)) + 'Basic ' + auth) else: request = url request.add_data(data) @@ -212,3 +217,4 @@ def mungeEmail(s): # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: +