适用于Python的Google API v4 KeyError:“ _ module”

时间:2018-06-21 19:21:20

标签: python python-2.7 google-api

我不是真正的开发人员,但我需要经常设计工具。

尝试为Python设置Google API v4遇到麻烦:

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

遵循所有说明。

执行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

修复,我安装了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.

遇到另一个错误:

# 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'

这时有点卡住,有什么建议吗?

只需使用标准的设置即可进行全新安装:

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

1 个答案:

答案 0 :(得分:0)

这也发生在我身上。您必须将凭据.json文件重命名为client_secret.json。进行此更改后,它对我有用。