Shawn Q
Shawn Q

Reputation: 27

Google API v4 for Python KeyError: '_module'

I'm not really a developer, but I need to engineer tools often.

Having trouble trying to set up Google API v4 for Python:

https://developers.google.com/sheets/api/quickstart/python

Followed all instructions.

When executing the quickstart.py:

# python quickstart.py
Traceback (most recent call last):
  File "quickstart.py", line 7, in <module>
    from oauth2client import file, client, tools
ImportError: No module named oauth2client

To fix I installed oauth2client:

# pip install oauth2client
Collecting oauth2client
  Downloading https://files.pythonhosted.org/packages/82/d8/3eab58811282ac7271a081ba5c0d4b875ce786ca68ce43e2a62ade32e9a8/oauth2client-4.1.2-py2.py3-none-any.whl (99kB)
    100% |████████████████████████████████| 102kB 5.7MB/s 
Requirement already satisfied (use --upgrade to upgrade): six>=1.6.1 in /usr/lib/python2.7/site-packages (from oauth2client)
Requirement already satisfied (use --upgrade to upgrade): rsa>=3.1.4 in /usr/lib/python2.7/site-packages (from oauth2client)
Requirement already satisfied (use --upgrade to upgrade): httplib2>=0.9.1 in /usr/lib/python2.7/site-packages (from oauth2client)
Requirement already satisfied (use --upgrade to upgrade): pyasn1>=0.1.7 in /usr/lib/python2.7/site-packages (from oauth2client)
Requirement already satisfied (use --upgrade to upgrade): pyasn1-modules>=0.0.5 in /usr/lib/python2.7/site-packages (from oauth2client)
Installing collected packages: oauth2client
Successfully installed oauth2client-4.1.2
You are using pip version 8.1.2, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Ran into another error:

# python quickstart.py
Traceback (most recent call last):
  File "quickstart.py", line 12, in <module>
    creds = store.get()
  File "/usr/lib/python2.7/site-packages/oauth2client/client.py", line 407, in get
    return self.locked_get()
  File "/usr/lib/python2.7/site-packages/oauth2client/file.py", line 54, in locked_get
    credentials = client.Credentials.new_from_json(content)
  File "/usr/lib/python2.7/site-packages/oauth2client/client.py", line 302, in new_from_json
    module_name = data['_module']
KeyError: '_module'

Kind of stuck at this point, any suggestions?

Just using a pretty standard setup, fresh install:

# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
# python --version
Python 2.7.5

Upvotes: 0

Views: 1157

Answers (1)

Erik Brown
Erik Brown

Reputation: 26

This happened to me too. You have to rename the credentials.json file to client_secret.json. After making this change it worked for me.

Upvotes: 0

Related Questions