本文介绍了Google API quickstart.py错误KeyError:'_module'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Gmail API。我的客户机秘密文件已下载并适用于Ruby。当我尝试quickstart.py(python)版本时,我得到这个错误

 文件quickstart.py,第70行,in <模块> 
main()
在main
credentials = get_credentials()中创建第55行quickstart.py文件
get_credentials $ b中的第38行quickstart.py文件$ b credentials = store.get()
文件/Library/Python/2.7/site-packages/oauth2client/client.py,第374行,获取
返回self.locked_get()
文件/Library/Python/2.7/site-packages/oauth2client/file.py,第79行,位于locked_get
credentials = Credentials.new_from_json(content)
文件/ Library / Python / 2.7 / site-packages / oauth2client / client.py,第281行,在new_from_json中
module = data ['_ module']
KeyError:'_module'

我根本没有更改文件,只是将client_secret.json添加到该工作目录,并安装了google-api-python-client。我的Python代码来自这里:

解决方案
oauth2client试图从不正确结构的json文件中加载证书。



也许Ruby客户端使用不同的文件格式,但我会感到惊讶。你确定你不小心将 client_secret.json 保存为〜/ .credentials / gmail-quickstart.json 吗?无论如何,删除〜/ .credentials / gmail-quickstart.json 并重新进行身份验证都会生成一个新凭据文件的结构正确。


Using Gmail API. My client secret file is downloaded and working for Ruby. When I try the quickstart.py (python) version I get this error

File "quickstart.py", line 70, in <module>
    main()
  File "quickstart.py", line 55, in main
    credentials = get_credentials()
  File "quickstart.py", line 38, in get_credentials
    credentials = store.get()
  File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 374, in get
    return self.locked_get()
  File "/Library/Python/2.7/site-packages/oauth2client/file.py", line 79, in locked_get
    credentials = Credentials.new_from_json(content)
  File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 281, in new_from_json
    module = data['_module']
KeyError: '_module'

I have not changed the file at all, just added the client_secret.json to that working directory and also install the google-api-python-client. My python code came from here: https://developers.google.com/gmail/api/quickstart/python

解决方案

oauth2client is trying to load credentials from a json file with an incorrect structure.

Maybe the Ruby client uses a different file format but I'd be surprised. Are you sure you didn't save client_secret.json as ~/.credentials/gmail-quickstart.json accidentally?

Regardless, removing ~/.credentials/gmail-quickstart.json and re-authenticating will generate a new credentials file with the correct structure.

这篇关于Google API quickstart.py错误KeyError:'_module'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:02