Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Error: Google Analytics API Authorization

I'm trying to run the sample provided here https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-py for authorization.

I've noticed from other questions in SO that (ImportError: cannot import name SignedJwtAssertionCredentials) SignedJwtAssertionCredentials has been removed and therefore could not be imported.

So, I started to follow the solutions provided both on the GitHub page (https://github.com/google/oauth2client/issues/401) and StackOverflow. So far, nothing worked, I'm still seeing the same error. Following is my code.

import argparse

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

import httplib2
from oauth2client import client
from oauth2client import file
from oauth2client import tools

And, this is the error I'm receiving on running the above code.

ImportError: cannot import name ServiceAccountCredentials

As I'm a complete newbie in this space, I tried to do this for both versions of OAuth (2.0.0 and 1.5.2). I also tried it after installing pyopenssl, but still failed.

like image 584
FreeSid91 Avatar asked Mar 01 '16 21:03

FreeSid91


3 Answers

It seems oauth2client installation is unsuccessful. Try

pip install --upgrade google-api-python-client

like image 73
schafle Avatar answered Oct 24 '22 22:10

schafle


Installing pyopenssl fixed the issue for me:

pip install pyopenssl

Based on this answer.

like image 38
Blairg23 Avatar answered Oct 24 '22 21:10

Blairg23


I had similar issues where I was getting cannot import name xxxx error. It turn out I had old *.pyc files in my environment from an older oauth2client version. Even though I updated to the lastest oauth2client version, the *.pyc files were getting used when I tried to run. I simply deleted the oauth2client *.pyc files and then reran my program without any issues.

Even if you upgrade to use the latest google-api-python-client... you'll want to make sure any *.pyc files from the old library have been removed.

like image 31
Steve Scherer Avatar answered Oct 24 '22 22:10

Steve Scherer