0

我正在使用 python 版本 3 和 PyDrive 来连接 Google 电子表格。我成功打开浏览器并进行身份验证。但是,在那之后我得到一个错误并且程序无法继续。

这是一条错误消息

Authentication successful.
Traceback (most recent call last):
File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/pydrive/files.py", line 369, in _FilesInsert
http=self.http)
File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/googleapiclient/http.py", line 812, in execute
_, body = self.next_chunk(http=http, num_retries=num_retries)
File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/googleapiclient/http.py", line 916, in next_chunk
raise ResumableUploadError(resp, content)
googleapiclient.errors.ResumableUploadError: <HttpError 403 "Project 895099846013 is not found and cannot be used for API calls. If it is recently created, enable Drive API by visiting then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "drive_control.py", line 10, in <module>
   file.Upload()
 File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/pydrive/files.py", line 285, in Upload
self._FilesInsert(param=param)
 File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/pydrive/auth.py", line 75, in _decorated
return decoratee(self, *args, **kwargs)
 File "/home/PycharmProjects/misc/.venv/lib/python3.5/site-packages/pydrive/files.py", line 371, in _FilesInsert
raise ApiRequestError(error)
pydrive.files.ApiRequestError: <HttpError 403 "Project 895099846013 is not found and cannot be used for API calls. If it is recently created, enable Drive API by visiting url If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">

这是我从 pydrive.auth 导入 GoogleAuth 从 pydrive.drive 导入 GoogleDrive 的代码

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)
file = drive.CreateFile({'title': 'Hello.txt'})
file.SetContentString('Hello World!')
file.Upload()
4

1 回答 1

1

此错误在回溯中有明确的描述:

403 "项目895099846013未找到,不能用于API调用。如果是最近创建的,通过访问url启用Drive API

在您的帐户中,您必须具有 Google Drive API 的启用状态。

您可以在Console Developer 工具栏中看到它

如果您没有看到它,请按照说明进行操作

于 2017-06-26T20:09:52.140 回答