How to upload documents with new python-gdata (2.0.16)?

这一生的挚爱 提交于 2019-12-04 19:23:48

I was having issues with this recently too. This worked for me:

import gdata.docs.data
import gdata.docs.client

client = gdata.docs.client.DocsClient(source='your-app')
client.api_version = "3"
client.ssl = True
client.ClientLogin("your@email.com", "password", client.source)

filePath = "/path/to/file"
newResource = gdata.docs.data.Resource(filePath, "document title")

media = gdata.data.MediaSource()
media.SetFileHandle(filePath, 'mime/type')

newDocument = client.CreateResource(newResource, create_uri=gdata.docs.client.RESOURCE_UPLOAD_URI, media=media)

Edit: Added the packages to import to avoid confusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!