我有一个Google电子表格,我可以用我的用户访问,我想通过python3.6在Windows中阅读它的一系列内容。在
我在这方面找到了一些很好的教程,因此我构建了以下内容:
def get_credentials():
# "Gets valid user credentials from storage."
credential_dir = os.getcwd();
credential_path = os.path.join(credential_dir, 'client_secret.json');
print(credential_path);
store = Storage(credential_path);
credentials = store.get();
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
credentials = get_credentials();
我创造了一个客户_secret.json文件工作目录中的文件,以下是伪内容(结构不变,但键已更改):
^{pr2}$我认为一切都应该成功,但是失败的原因是:
C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\client_secret.json
Traceback (most recent call last):
File "C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\MySolution.py", line 135, in <module>
credentials = get_credentials();
File "C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\MySolution.py", line 67, in get_credentials
credentials = store.get();
File "C:\Program Files\Python36\lib\site-packages\oauth2client\client.py", line 407, in get
return self.locked_get()
File "C:\Program Files\Python36\lib\site-packages\oauth2client\file.py", line54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "C:\Program Files\Python36\lib\site-packages\oauth2client\client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
Press any key to continue . . .
我还是Python的新手,googledocs的新手,我看不出哪里出了问题。我能想象的是客户的结构_secret.json文件是不正确的,但是我从googleapi管理器下载了客户机机密json文件,并直接从那里保存了它(并且没有做任何更改)。在
除此之外,哪里出了问题?在
致以最诚挚的问候
试着别打电话
只是暂时用
^{pr2}$也就是说,让代码到达检索凭据的回退方法,该方法以以下开头:
^{3}$在我的例子中,我已经从我的googleapi帐户下载了}期望的结构不匹配。可能在过去它返回None,但现在它抛出一个异常并打破了这个例子。一旦我排除了这个调用,我就可以在浏览器中验证这个应用程序,并在控制台中获得它的输出。在
client_secret.json
,但是它的结构显然与{相关问题 更多 >
编程相关推荐