我是Python新手并尝试使用Google Drive Apis,但面临此问题。
错误我在运行<div id="split">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent molestie felis eu nisl gravida, sed molestie tortor egestas. Integer a velit quis mauris vehicula sagittis nec in dui. Suspendisse potenti. In hac habitasse platea dictumst. Donec convallis pharetra diam, id rutrum purus porta eu. Morbi feugiat mauris sed viverra volutpat. Pellentesque aliquam, nibh ac accumsan vehicula, ex justo blandit quam, at rhoncus turpis neque id est.
</div>
python quickstart.py
以下是 quickstart.py 文件的外观。
Traceback (most recent call last):
File "quickstart.py", line 9, in <module>
creds = store.get()
File "/usr/local/lib/python3.6/site-packages/oauth2client/client.py", line 407, in get
return self.locked_get()
File "/usr/local/lib/python3.6/site-packages/oauth2client/file.py", line 54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "/usr/local/lib/python3.6/site-packages/oauth2client/client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
更新 我检查过,结果是第一次运行时会自动生成 credentials.json 文件,出于某种原因,这种情况不会发生。
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# Setup the Drive v3 API
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('drive', 'v3', http=creds.authorize(Http()))
# Call the Drive v3 API
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print('{0} ({1})'.format(item['name'], item['id']))
此键 _module 假设存在于 credentials.json 文件中,这就是抛出此错误的原因。不确定缺少什么。有人可以告诉我如何解决这个问题。
答案 0 :(得分:1)
Similar issue here尝试从目录中删除这两个文件 - “credentials.json”和“client_secret.json”。然后重新生成您的凭据并重新创建“client_secret.json”,这对我有用。