Leonard
Leonard

Reputation: 53

Python Google drive API cannot insert media file using mediaFileUpload

I tried submitting this to Google support but they referred me to stack overflow but there's an issue when running the insert function for the Google Drive API using the python library googleapiclient.

Python Broken API Function Call

When trying to insert a MediaFileUpload as per the instructions in

https://developers.google.com/drive/v2/reference/files/insert

How do I submit lines of code in a comment?

UPDATED:

http = httplib2.Http()
http = credentials.authorize(http)
service = build('drive', 'v2', http=http)
media_body = MediaFileUpload('test.csv', mimetype='application/vnd.ms-excel', resumable=True)

body = {
'title': 'test.csv',
'description': 'test description',
'mimeType': 'application/vnd.ms-excel'
}
file = service.files().insert(body=body,media_body=media_body).execute()

It doesn't actually work, you keep getting an error message saying a string or MediaFile type is required File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 692, in method raise TypeError('media_filename must be str or MediaUpload.')

Does anyone know why media_body can't be MediaFileUpload when the documentation clearly says use MediaFileUpload?

Upvotes: 5

Views: 2377

Answers (1)

davejagoda
davejagoda

Reputation: 2528

From the comments thread, here was the answer that ended up resolving the issue:

Upgrade to the latest google-api-python-client (version 1.4.2 as of this writing).

Upvotes: 1

Related Questions