Update a file with convert to Google driver with pydrive Gives: ApiRequestError: HttpError 500 Error

1.5k views Asked by At

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

1

There are 1 answers

0
zooglash On

FWIW, this code worked for me (using PyDrive):

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