2

I am trying to update an existing file in Google drive using python script.

The code that I am using is:

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.

As I said when I am running the code the following error occurs:

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

Everything is good if I don't use {'convert':True} tag in Upload, but I really need it because I want the file to be converted.

I'm trying to upload an .xlsx file

4

1 回答 1

1

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

f = drive.CreateFile({'title':'test.csv', 'mimeType':'text/csv'})
f.SetContentString('a,b\n1,2')
f.Upload(param={'convert': True})
于 2015-05-27T07:29:49.783 回答