考虑以下使用PyDrive模块的代码:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
file = drive.CreateFile({'title': 'test.txt'})
file.Upload()
file.SetContentString('hello')
file.Upload()
file.SetContentString('')
file.Upload() # This throws an exception.
创建文件并更改其内容工作正常,直到我尝试通过将内容字符串设置为空字符串来擦除内容。这样做会引发此异常:
pydrive.files.ApiRequestError
<HttpError 400 when requesting
https://www.googleapis.com/upload/drive/v2/files/{LONG_ID}?alt=json&uploadType=resumable
returned "Bad Request">
当我查看云端硬盘时,我看到已成功创建test.txthello文件,其中包含文本。但我预计它会是空的。
如果我将空字符串更改为任何其他文本,则文件会更改两次而不会出现错误。虽然这并没有清除内容,所以这不是我想要的。
江户川乱折腾
相关分类