【问题标题】:Update a file with convert to Google driver with pydrive Gives: ApiRequestError: HttpError 500 Error使用 pydrive 更新文件并转换为 Google 驱动程序给出:ApiRequestError: HttpError 500 Error
【发布时间】:2014-11-13 07:38:34
【问题描述】:

我正在尝试使用python script 更新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">

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

我正在尝试上传 .xlsx 文件

【问题讨论】:

  • 尝试:({'convert':true})
  • Its not working. Ive 也尝试过 ({'convert':'true'})
  • 有什么理由不使用 Google 的示例和客户端库?
  • 如果找不到解决方案,我会尝试 google-api。我真的很好奇为什么这不起作用
  • 可能您使用的代码中的某些内容 Google 没有上传其插入内容。因此,无法知道该代码是否支持转换。你在那里。

标签: python python-2.7 google-drive-api pydrive


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    相关资源
    最近更新 更多