4
votes

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?

1
I have a program very similar to this that is currently working. Can you update your question with more of your code?davejagoda
Sure that's not a problem.Leonard
Comments formatting is sort of limited - best is to update the code snippet in your original question.davejagoda
I've updated the code, there's a bit of redundancy in the body and media_body request but that should be ok.Leonard
How are you authenticating?davejagoda

1 Answers

1
votes

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).