mooselau / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

TypeError when using oauth2 store #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When I delete my analytics.dat file and try again. It works without an issue. 
It's only when it's trying to re-use the credentials that I'm seeing this.

/usr/bin/python2 /home/numkem/src/foo/run.py
Traceback (most recent call last):
  File "/home/numkem/src/foo/run.py", line 5, in <module>
    import application
  File "/home/numkem/src/foo/application/__init__.py", line 42, in <module>
    from views import *
  File "/home/numkem/src/foo/application/views/std.py", line 3, in <module>
    from application.google_analytics import service
  File "/home/numkem/src/foo/application/google_analytics.py", line 75, in <module>
    credentials.refresh(http)
  File "/home/numkem/src/foo/application/../lib/oauth2client/client.py", line 516, in refresh
    self._refresh(http.request)
  File "/home/numkem/src/foo/application/../lib/oauth2client/client.py", line 663, in _refresh
    self._do_refresh_request(http_request)
  File "/home/numkem/src/foo/application/../lib/oauth2client/client.py", line 677, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/home/numkem/src/foo/application/../lib/oauth2client/client.py", line 861, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/home/numkem/src/foo/application/../lib/oauth2client/client.py", line 977, in _generate_assertion
    private_key, self.private_key_password), payload)
  File "/home/numkem/src/foo/application/../lib/oauth2client/crypt.py", line 131, in from_string
    pkey = crypto.load_pkcs12(key, password).get_privatekey()
  File "/home/numkem/src/foo/venv/lib/python2.7/site-packages/OpenSSL/crypto.py", line 2223, in load_pkcs12
    parse_result = _lib.PKCS12_parse(p12, passphrase, pkey, cert, cacerts)
TypeError: initializer for ctype 'char *' must be a str or list or tuple, not 
unicode

This is the main part of my code:

http = httplib2.Http()
storage = Storage(os.path.join(os.path.dirname(__file__), '..', 'share', 
'analytics.dat'))
credentials = storage.get()

if credentials is None or credentials.invalid:
    f = file(os.path.join(os.path.dirname(__file__), '..', app.config['GOOGLE_API_KEYPATH']), 'rb')
    key = f.read()
    f.close()

    credentials = SignedJwtAssertionCredentials(
        app.config['GOOGLE_API_EMAIL'], key,
        scope='https://www.googleapis.com/auth/analytics.readonly')
    storage.put(credentials)
else:
    credentials.refresh(http)

http = credentials.authorize(http)
service = build('analytics', 'v3', http=http)

The crash happens on the "credentials.refresh(http)"

This is on Python 2.7.6 running on ArchLinux.

Original issue reported on code.google.com by num...@gmail.com on 27 Feb 2014 at 1:41

GoogleCodeExporter commented 9 years ago
I am currently having the exact same problem. Have you found a solution for 
this issue?

Best regards,

Sebastian.

Original comment by gnuse...@gmail.com on 14 May 2014 at 11:12

GoogleCodeExporter commented 9 years ago
I never did, I only found a solution that wouldn't use any stored credentials 
and it works rather well. I don't know whats the speed penalty if you are doing 
a lot of requests but for me it works well enough.

Original comment by num...@gmail.com on 14 May 2014 at 11:48

GoogleCodeExporter commented 9 years ago
SignedJwtAssertionCredentials do not need to be refreshed.

Original comment by jasm...@google.com on 16 May 2014 at 1:56

GoogleCodeExporter commented 9 years ago
My mistake, they do.

However I've also fixed the bug causing the crash. I'll push it to the 
github.com/google/oauth2client soon.

Original comment by jasm...@google.com on 16 May 2014 at 2:50

GoogleCodeExporter commented 9 years ago
If you want to patch before it gets out w/ my fix,

Line 131 in crypt.py, was
        pkey = crypto.load_pkcs12(key, password).get_privatekey()
should be
        pkey = crypto.load_pkcs12(key, str(password)).get_privatekey()

Original comment by jasm...@google.com on 16 May 2014 at 2:54

GoogleCodeExporter commented 9 years ago
The patch seems not to be applied to github.com/google/oauth2client yet.
Is there a plan to push the fix?

Original comment by kazuhiro...@g.hde.co.jp on 24 Jul 2014 at 3:29