【发布时间】:2019-10-20 05:24:45
【问题描述】:
我正在尝试使用 python 在谷歌日历中创建一个事件。错误在于使用 .get() 似乎存在问题。我对 google calendar api 不是很有经验,因为这是我的第一个程序,所以我无法再缩小范围,所以有人可以帮我解决这个问题吗?
我重新创建了视频中建议的代码 https://developers.google.com/calendar/create-events 我将 storage.json 更改为 credentials.json
触发错误的行是这个,
store = file.Storage('credentials.json')
creds = store.get()
该文件无法运行并吐出一堆错误。
这些是错误:
Traceback (most recent call last):
File "goal_insert.py", line 9, in module>
creds = store.get()
File "/Users/name/Library/Python/2.7/lib/python/site-packages/oauth2client/client.py", line 407, in get
return self.locked_get()
File "/Users/name/Library/Python/2.7/lib/python/site-packages/oauth2client/file.py", line 54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "/Users/name/Library/Python/2.7/lib/python/site-packages/oauth2client/client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
【问题讨论】:
-
你检查过这个相关的SO post吗?同时,您可以尝试将
creds = store.get()替换为creds = None的解决方案。 -
@jess 我注释掉了该行和以下行,它似乎有效。但是,这会导致每次运行时都会更改凭据文件的问题。所以我最终读取了最初的 JSON 文件,在程序完成后,它会将该信息转储回 JSON 文件,使其处于与开始时相同的状态。但是,我不确定这是否会在我对此进行扩展时起作用,所以我想我可能需要修复它。我正在查看另一个线程 rn,看看我可以从中使用什么。
标签: python json google-calendar-api google-oauth google-apis-explorer