Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some python2->3 string issues #671

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gcloud/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import json
import six

_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module

Expand Down Expand Up @@ -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

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


message = content
errors = ()

Expand Down
4 changes: 4 additions & 0 deletions gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""Create / interact with gcloud storage connections."""

import json
import six

from six.moves.urllib.parse import urlencode # pylint: disable=F0401

Expand Down Expand Up @@ -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

This comment was marked as spam.


if content and expect_json:
content_type = response.get('content-type', '')
if not content_type.startswith('application/json'):
Expand Down