问题描述
我不是真正的开发人员,但我需要经常设计工具.
I'm not really a developer, but I need to engineer tools often.
尝试为 Python 设置 Google API v4 时遇到问题:
Having trouble trying to set up Google API v4 for Python:
https://developers.google.com/sheets/api/quickstart/python
遵循所有说明.
执行quickstart.py时:
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
为了修复,我安装了 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.
遇到另一个错误:
# 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
推荐答案
这也发生在我身上.您必须将credentials.json 文件重命名为client_secret.json.进行此更改后,它对我有用.
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.
这篇关于适用于 Python KeyError 的 Google API v4:&#39;_module&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!