Skip to content

decode content in build#1

Closed
chacken wants to merge 1 commit into
pferate:python3from
chacken:python3
Closed

decode content in build#1
chacken wants to merge 1 commit into
pferate:python3from
chacken:python3

Conversation

@chacken
Copy link
Copy Markdown

@chacken chacken commented Jan 18, 2015

Not entirely sure if it's okay to automatically decode to utf-8 by default.

Here's an example of the bug.

web_1     |   File "/code/makers/views/accounts.py", line 133, in code
web_1     |     service = discovery.build('plus', 'v1', http=h)
web_1     |   File "/usr/local/lib/python3.4/site-packages/oauth2client/util.py", line 132, in positional_wrapper
web_1     |     return wrapped(*args, **kwargs)
web_1     |   File "/usr/local/lib/python3.4/site-packages/googleapiclient/discovery.py", line 227, in build
web_1     |     service = json.loads(content)
web_1     |   File "/usr/local/lib/python3.4/json/__init__.py", line 312, in loads
web_1     |     s.__class__.__name__))
web_1     | TypeError: the JSON object must be str, not 'bytes'

@chacken
Copy link
Copy Markdown
Author

chacken commented Jan 18, 2015

Completely forgot to account for py < 3 .. what's the best way to handle that?

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.55%) when pulling de74d56 on chacken:python3 into ce5c5cf on pferate:python3.

@maxwell-k
Copy link
Copy Markdown

This is an important change for me, thanks for spotting it!

The oauth2client library also supports Python 2 with:

if six.PY3 and isinstance(content, bytes):                                   
    content = content.decode('utf-8')

for example at https://github.com/google/oauth2client/blob/master/oauth2client/client.py#L774

I've taken this approach in 08dfb1f

@pferate
Copy link
Copy Markdown
Owner

pferate commented Jan 28, 2015

I'm going to close this PR and use the other PR (#2) from @maxwell-k. Thanks for the help!

@pferate pferate closed this Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants