diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index 78f641118031..3f3842c22a19 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -18,6 +18,7 @@ """ import json +import six _HTTP_CODE_TO_EXCEPTION = {} # populated at end of module @@ -171,6 +172,9 @@ def make_exception(response, content, use_json=True): :rtype: instance of :class:`GCloudError`, or a concrete subclass. :returns: Exception specific to the error response. """ + if six.PY3 and isinstance(content, bytes): + content = content.decode('utf-8') # pragma: NO COVER Py3K + message = content errors = () diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index fabb1edfb94d..58f6369bb884 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -15,6 +15,7 @@ """Create / interact with gcloud storage connections.""" import json +import six from six.moves.urllib.parse import urlencode # pylint: disable=F0401 @@ -235,6 +236,9 @@ def api_request(self, method, path, query_params=None, if not 200 <= response.status < 300: raise make_exception(response, content) + if six.PY3 and isinstance(content, bytes): + content = content.decode('utf-8') # pragma: NO COVER Py3K + if content and expect_json: content_type = response.get('content-type', '') if not content_type.startswith('application/json'):