【发布时间】:2021-02-20 06:17:37
【问题描述】:
我正在尝试使用 pydrive 删除共享驱动器上的文件,但我无法删除该文件。 当我获得有关驱动器上文件的信息时,它会显示文件 ID,但是当我使用“Trash() 函数”时,它会显示错误为“找不到文件:XXX”。
开发环境
ubuntu 20.04 on docker
python 3.7
pydrive 1.3.1
代码内容
from pydrive.auth import GoogleAuth
from oauth2client.service_account import ServiceAccountCredentials
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
scope = ['https://www.googleapis.com/auth/drive']
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name("client_secrets.json", scope)
drive = GoogleDrive(gauth)
for f in drive.ListFile({'driveId': 'AAA', 'corpora': 'drive', 'includeItemsFromAllDrives': 'true',
'supportsAllDrives': 'true', 'q': 'title = "lock" and trashed = false'}).GetList():
print(f['title'], ' \t', f['id'])
f_txt = drive.CreateFile(f)
f_txt.Trash()
错误内容
root@test:~/reman/src/For_lambda/refer# python3 delete_lockfile.py
lock 10xM-FIkMoyRIb7PC1VBxZZJn_QePxy-I
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pydrive/files.py", line 410, in _FilesTrash
http=self.http)
File "/usr/local/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/googleapiclient/http.py", line 915, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError:
<HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/10xM-FIkMoyRIb7PC1VBxZZJn_QePxy-I/trash?alt=json returned
"File not found: 10xM-FIkMoyRIb7PC1VBxZZJn_QePxy-I".
Details: "File not found: 10xM-FIkMoyRIb7PC1VBxZZJn_QePxy-I">
如上所示,我可以得到[fileid: 10xM-FIkMoyRIb7PC1VBxZZJn_QePxy-I],但是当我删除文件时,它显示为未找到。
我不知道发生了什么。请帮忙!谢谢,
【问题讨论】: