-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Ensuring response from httplib2 is treated as str in Python 2 and bytes in Python3 #724
Ensuring response from httplib2 is treated as str in Python 2 and bytes in Python3 #724
Conversation
@@ -256,7 +256,7 @@ def api_request(self, method, path, query_params=None, | |||
content_type = response.get('content-type', '') | |||
if not content_type.startswith('application/json'): | |||
raise TypeError('Expected JSON, got %s' % content_type) | |||
return json.loads(content) | |||
return json.loads(content.decode('utf-8')) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…nnection.api_request is decoded to a string before being passed to json.loads
…o use six.binary_type
…intention clearer
a66cb5c
to
62e13d7
Compare
- Incorporates changes from googleapis#724. - Also requires httplib2 from HEAD since the bytes/unicode header issues have not been released on PyPI yet.
- Incorporates changes from googleapis#724. - Also requires httplib2 from HEAD since the bytes/unicode header issues have not been released on PyPI yet.
@craigloftus Thanks for doing this work. I have incorporated it into #756 to keep this from bit-rotting too much as we make more updates to master. Please re-open or comment if you have any issues with this. |
@dhermes No worries. I learnt a lot and look forward to no longer depending on my fork. |
When using Python 3
httplib2
returns response content asbytes
, but the content isstr
in Python 2. This causes problems when passing the content tojson.loads
, which requiresstr
always.Tests were passing previously because they were mocking the response by
httplib2
as astr
. These tests have been changed to use theb
notation, which resolves tostr
in Python 2 andbytes
in Python 3.This is the follow-up from PR #697.