Skip to content

Commit 03b98c1

Browse files
committed
handle strings encoding in hash_pass with Python3
1 parent 326001d commit 03b98c1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/vsc/utils/rest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from future.utils import iteritems
4343

4444
from vsc.utils import fancylogger
45-
from vsc.utils.py2vs3 import HTTPSHandler, Request, build_opener, urlencode
45+
from vsc.utils.py2vs3 import HTTPSHandler, Request, build_opener, is_py3, urlencode
4646

4747

4848
class Client(object):
@@ -195,7 +195,18 @@ def urlencode(self, params):
195195
def hash_pass(self, password, username=None):
196196
if not username:
197197
username = self.username
198-
return 'Basic ' + base64.b64encode('%s:%s' % (username, password)).strip()
198+
199+
credentials = '%s:%s' % (username, password)
200+
if is_py3():
201+
# convert credentials into bytes
202+
credentials = credentials.encode('utf-8')
203+
204+
encoded_credentials = base64.b64encode(credentials).strip()
205+
if is_py3():
206+
# convert back to string
207+
encoded_credentials = str(encoded_credentials, 'utf-8')
208+
209+
return 'Basic ' + encoded_credentials
199210

200211
def get_connection(self, method, url, body, headers):
201212
if not self.url.endswith('/') and not url.startswith('/'):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
]
4545

4646
PACKAGE = {
47-
'version': '3.4.3',
47+
'version': '3.4.4',
4848
'author': [sdw, jt, ag, kh],
4949
'maintainer': [sdw, jt, ag, kh],
5050
# as long as 1.0.0 is not out, vsc-base should still provide vsc.fancylogger

0 commit comments

Comments
 (0)