Google API quickstart.py error KeyError: '_module'
oauth2client is trying to load credentials from a json file with an incorrect structure.
Maybe the Ruby client uses a different file format but I'd be surprised. Are you sure you didn't save client_secret.json
as ~/.credentials/gmail-quickstart.json
accidentally?
Regardless, removing ~/.credentials/gmail-quickstart.json
and re-authenticating will generate a new credentials file with the correct structure.
Try replacing creds = store.get()
with creds = None
temporarily. If this works, you can refactor your code to always start with flow-based credentials instantiation. This worked for me. It seems Google samples are out of sync with their oauth2client.
In this GitHub issue: error "KeyError: '_module'" when running gdrive_upload.py
sputnik-dev answared on 10 Jan 2016:
If someone have the same issue :
auth_token.txt
andclient_secret.json
are not the same! Don't link theclient_secret.json
from google API console. The file will be automatically created by the script.
Wrong way: gauth.SaveCredentialsFile("client_secret.json")
Right way: gauth.SaveCredentialsFile("<any random name>.json")
Extra:
PyDrive code that automate google drive api authetication. Use the browser just one time to authenticate and never more. It saves your credential data on mycreds.json
:)
from pydrive.auth import GoogleAuthfrom pydrive.drive import GoogleDrivegauth = GoogleAuth()gauth.LoadCredentialsFile("mycreds.json")if gauth.credentials is None: gauth.LocalWebserverAuth()elif gauth.access_token_expired: gauth.Refresh()else: gauth.Authorize()gauth.SaveCredentialsFile("mycreds.json")