简体   繁体   English

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

[英]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: 尝试为Python设置Google API v4时遇到问题:

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

Followed all instructions. 遵循所有说明。

When executing the quickstart.py: 执行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: 修复我安装了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

This happened to me too. 这也发生在我身上。 You have to rename the credentials.json file to client_secret.json. 您必须将凭据.json文件重命名为client_secret.json。 After making this change it worked for me. 进行此更改后,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM