gpt4 book ai didi

python - 使用 pydrive 转换为 Google 驱动程序更新文件给出 : ApiRequestError: HttpError 500 Error

转载 作者:太空宇宙 更新时间:2023-11-04 05:57:29 25 4
gpt4 key购买 nike

我正在尝试使用 python 脚本 更新 Google drive 中的现有文件。

我使用的代码是:

fileID = wasFileUploadedBefore(drive, reportName) #this gets the fileID if it's already in GDrive
if fileID != 0:
reportFile = drive.CreateFile({'id': fileID})
else:
reportFile = drive.CreateFile({'title':reportName, 'mimeType':'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
reportFile.SetContentFile(reportName)
reportFile.Upload({'convert':True}) #convert=true is to convert the file to GoogleDrive Spreadsheet.

正如我所说,当我运行代码时出现以下错误:

raise ApiRequestError(error)
ApiRequestError: <HttpError 500 when requesting https://www.googleapis.com/upload/drive/v2/....&convert=true&alt=json returned "Internal Error">

如果我不在上传中使用 {'convert':True} 标签,一切都很好,但我真的需要它,因为我想要转换文件。

我正在尝试上传 .xlsx 文件

最佳答案

FWIW,这段代码对我有用(使用 PyDrive):

f = drive.CreateFile({'title':'test.csv', 'mimeType':'text/csv'})
f.SetContentString('a,b\n1,2')
f.Upload(param={'convert': True})

关于python - 使用 pydrive 转换为 Google 驱动程序更新文件给出 : ApiRequestError: HttpError 500 Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26903632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com