Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

broken encoding with python 3.4 (fix inside) #294

Closed
richiverse opened this issue Aug 28, 2015 · 5 comments
Closed

broken encoding with python 3.4 (fix inside) #294

richiverse opened this issue Aug 28, 2015 · 5 comments

Comments

@richiverse
Copy link

context:

.../site-packages/oauth2client/client.py", line 1515, in __init__
self.private_key = base64.b64encode(private_key) 
File ".../venv/lib/python3.4/base64.py", line 62, in b64encode
encoded = binascii.b2a_base64(s)[:-1]
TypeError: 'str' does not support the buffer interface

Changing line 1515 in oauth2client/client.py from this:

self.private_key = base64.b64encode(private_key)

to this:

self.private_key = base64.b64encode(private_key.encode('ascii'))

fixed my issue.

reference:
http://stackoverflow.com/questions/27160352/when-convert-to-base-64-typeerror-str-does-not-support-the-buffer-interface

@dhermes
Copy link
Contributor

dhermes commented Aug 29, 2015

Can you do a pip3 show oauth2client to determine what version you have?

If this hasn't already been resolved in a release, it probably will be in 1.5.0 (#292)

@richiverse
Copy link
Author

---
Metadata-Version: 1.1
Name: oauth2client
Version: 1.4.12
Summary: OAuth 2.0 client library
Home-page: http://github.com/google/oauth2client/
Author: Google Inc.
Author-email: UNKNOWN
License: Apache 2.0
Location: .../venv/lib/python3.4/site-packages
Requires: httplib2, pyasn1, pyasn1-modules, rsa, six

@dhermes
Copy link
Contributor

dhermes commented Aug 29, 2015

Thanks.

The latest version is 1.4.12: https://pypi.python.org/pypi/oauth2client/1.4.12

If you upgrade does the problem persist?

@dhermes
Copy link
Contributor

dhermes commented Aug 29, 2015

@dhermes
Copy link
Contributor

dhermes commented Aug 29, 2015

Traced the line to the current head, still an "issue": https://github.com/google/oauth2client/blob/b66838e48da243a7fefa7275044f6b5833ec1476/oauth2client/client.py#L1632

@richiverse For now, use bytes, but your suggestion should make it into the codebase, so thanks!

Easiest way (if you're reading from a file) is opening in read binary ('rb') mode.

dhermes added a commit to dhermes/oauth2client that referenced this issue Sep 17, 2015
JWT Assertion constructor converts the private key to base64
so it can be stored in JSON, but base64.b64encode fails on
the unicode type.

Fixes googleapis#294.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants