Fix a bug with encoding in Python 3 which was exposed by previous commit.
In Python 3, binascii.hexlify returns bytes, but we want a str.
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index ba1425a..622a275 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -605,7 +605,7 @@
self._tuple_from_url(url)
def _add_cache_busting_to_params(self, params):
- cache_busting_number = binascii.hexlify(os.urandom(8))
+ cache_busting_number = binascii.hexlify(os.urandom(8)).decode('ascii')
if isinstance(params, dict):
params['cache-busting'] = cache_busting_number
diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index 545ca00..0a84dd2 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -507,7 +507,8 @@
if 'password' in self.features['create_node']:
value = os.urandom(16)
- return NodeAuthPassword(binascii.hexlify(value), generated=True)
+ value = binascii.hexlify(value).decode('ascii')
+ return NodeAuthPassword(value, generated=True)
if auth:
raise LibcloudError(
diff --git a/libcloud/compute/deployment.py b/libcloud/compute/deployment.py
index 103315c..d0925b5 100644
--- a/libcloud/compute/deployment.py
+++ b/libcloud/compute/deployment.py
@@ -142,7 +142,9 @@
if self.name is None:
# File is put under user's home directory
# (~/libcloud_deployment_<random_string>.sh)
- self.name = 'libcloud_deployment_%s.sh' % (binascii.hexlify(os.urandom(4)))
+ random_string = binascii.hexlify(os.urandom(4))
+ random_string = random_string.decode('ascii')
+ self.name = 'libcloud_deployment_%s.sh' % (random_string)
def run(self, node, client):
"""
diff --git a/libcloud/compute/drivers/ecp.py b/libcloud/compute/drivers/ecp.py
index dff49c0..aa77440 100644
--- a/libcloud/compute/drivers/ecp.py
+++ b/libcloud/compute/drivers/ecp.py
@@ -102,7 +102,7 @@
#use a random boundary that does not appear in the fields
boundary = ''
while boundary in ''.join(fields):
- boundary = u(binascii.hexlify(os.urandom(16)))
+ boundary = binascii.hexlify(os.urandom(16)).decode('utf-8')
L = []
for i in fields:
L.append('--' + boundary)
diff --git a/libcloud/storage/drivers/azure_blobs.py b/libcloud/storage/drivers/azure_blobs.py
index 5512d70..06e4511 100644
--- a/libcloud/storage/drivers/azure_blobs.py
+++ b/libcloud/storage/drivers/azure_blobs.py
@@ -295,8 +295,9 @@
}
if extra['md5_hash']:
- extra['md5_hash'] = binascii.hexlify(
- base64.b64decode(b(extra['md5_hash'])))
+ value = binascii.hexlify(base64.b64decode(b(extra['md5_hash'])))
+ value = value.decode('ascii')
+ extra['md5_hash'] = value
meta_data = {}
for meta in metadata.getchildren():
@@ -344,8 +345,9 @@
}
if extra['md5_hash']:
- extra['md5_hash'] = binascii.hexlify(
- base64.b64decode(b(extra['md5_hash'])))
+ value = binascii.hexlify(base64.b64decode(b(extra['md5_hash'])))
+ value = value.decode('ascii')
+ extra['md5_hash'] = value
meta_data = {}
for key, value in response.headers.items():