0

I have followed Python Quick Start tutorial posted on https://developers.google.com/drive/v3/web/quickstart/python precisely and I am still getting the same error again and again (extremely frustrating):

File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'

It happens when client.py tries to process a secret-key.json file I downloaded from Google. Apparently client.py needs a _module dictionary key to be defined in json.

I've opened this secret-key.json file. Indeed there is a dictionary there but with no _module key in it (the content secret-key.json file is posted below). Apparently I am missing something while following the Quick Start tutorial. What is it?

Below are the description of the main steps I followed while creating the secret-key.json file.

First I have added the credentials to my project:

enter image description here

From "Which API are you using" pull down menu I have selected the "Google Drive API" as my choice.

From "Where will you be calling the API from" pull-down menu below I have selected "Other UI (e.g. Windows, CLI tools)" (Interesting that these configuration settings are totally missed in Google Quick Start tutorial).

Lastly I have selected "User Data" radio button at the bottom of the page.

I wonder if the selection I have made on this page are correct? (since none of these selection choices are covered in the tutorial).

All other options and configurations I set exactly as it was described in Quick Start.

Here is the secret key secret-key.json file I downloaded:

{"installed":{
"client_id":"12345678-vasdfasdfasfd.apps.googleusercontent.com",
"project_id":"project-name",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"asdfasfdadf-asfasfdasdf",
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

To create this json file I went to Credentials tab and clicked the blue "Create Credentials" button which showed me the list of choices:

enter image description here

I have selected "OAuth client ID" and it brought me to the next page:

enter image description here

Here I have checked "Other" radio button and hit "Create" button. The json file is now became available for download.

5
  • Could you make a Complete, Minimal and Verifiable example as I'm afraid I don't have any idea what is causing your issues, which .json files you're trying to access, etc... Commented Aug 1, 2017 at 16:08
  • Interesting that these configuration settings are totally missed in Google Quick Start tutorial no they aren't, in Step 1 the tutorial literally says "On the Add credentials to your project page, click the Cancel button." Commented Aug 1, 2017 at 16:35
  • You're ignoring the tutorial. Read what it says and follow it exactly. Commented Aug 1, 2017 at 16:36
  • Thanks for the note. I have used the Cancel button as well. It just doesn't help anyway. The question is still open. How to generate the json file that could be used with Google Drive Python Api. Commented Aug 1, 2017 at 18:42
  • If you follow the tutorial exactly, you shouldn't have this problem. You also went onto the "Credentials" tab rather than the "OAuth Consent Screen" tab suggested by the tutorial. Commented Aug 2, 2017 at 8:26

1 Answer 1

1

To make sure the Quick Start Python code runs you need to keep the secret-key.json file in the same directory where the executable python script is. This python script is hard-coded to copy the secret-key.json file into (os.path.expanduser('~') + '/.credentials') folder. After the secret-key.json is copied to .credentials folder it stays there even the credential settings are changed. You would need to delete that file in order for the Python/Drive API to be able to pick up the latest changes supplied by newly downloaded or updated json file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.