Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name SignedJwtAssertionCredentials

I'm trying to access a google app through the Python Client using this code to gain authorization (private info obviously redacted):

import gflags
import httplib2

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.tools import run

f = open('privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
    service_account_name='[email protected]',
    private_key=key,
    scope = 'https://www.googleapis.com/auth/calendar')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)

Yet I receive this error:

ImportError: cannot import name SignedJwtAssertionCredentials

I have installed the Google v3 API Python Client as well as OAuth2; I don't seem to be having any other problems with those modules, though I haven't used them much. Anyone know what's going on?

like image 551
user1427661 Avatar asked Dec 28 '12 00:12

user1427661


4 Answers

It seems like you havn't installed pyopenssl. Install via easy_install pyopenssl.

Libraries oauth2client.client
if HAS_OPENSSL:
  # PyOpenSSL is not a prerequisite for oauth2client, so if it is missing then
  # don't create the SignedJwtAssertionCredentials or the verify_id_token()
  # method.

  class SignedJwtAssertionCredentials(AssertionCredentials):
....
like image 32
alexander margraf Avatar answered Nov 14 '22 04:11

alexander margraf


I had this problem today and had to roll back from oauth2client version 2.0 to version 1.5.2 with:

pip install oauth2client==1.5.2
like image 115
Locane Avatar answered Nov 14 '22 04:11

Locane


The source repository was recently updated, to make use of the new code:

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

...
like image 9
Matt Avatar answered Nov 14 '22 06:11

Matt


As alexander margraf said you need PyOpenSSL to import SignedJwtAssertionCredentials

simply: pip install pyopenssl

REMEMBER: It will fail on Windows if you don't have OpenSSL Win32 libs installed http://slproweb.com/products/Win32OpenSSL.html (you need full package, not the light version). Also keep in mind you need to add it to your path var before installing pyopenssl

like image 4
Bartoszer Avatar answered Nov 14 '22 05:11

Bartoszer