2
votes

I'm trying to update a document on Google Docs/Drive after I created it, using the GData helpers for Python.

The new version of the API lacks documentation for Py.

client = gdata.docs.client.DocsClient(source=PluginConfig.APP_NAME)
client.http_client.debug = PluginConfig.DEBUG
client.client_login(
    PluginConfig.EMAIL,
    PluginConfig.PASSWORD,
    source=PluginConfig.APP_NAME,
    service=client.auth_service
)

[...]

# Upload the text file  
ms = gdata.data.MediaSource()
ms.SetFileHandle(file_path, content_type)
doc = gdata.docs.data.Resource(type='document', title=title)
doc.description = gdata.docs.data.Description(description)
doc = client.CreateResource(doc, media=ms)

doc = client.UpdateResource(doc, media=ms, new_revision=True)

Login and document creation work fine, but the Update() receives 400 Bad Request

Traceback (most recent call last):
  File "coll.py", line 301, in <module>
    main()
  File "coll.py", line 293, in main
    doc = client.UpdateResource(doc, media=ms, new_revision=True)
  File "/usr/lib/python2.7/dist-packages/gdata/docs/client.py", line 344, in update_resource
    uri_params=uri_params, **kwargs)
  File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1151, in update_file
    auth_token=auth_token, method='PUT')
  File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1085, in upload_file
    start_byte, self.file_handle.read(self.chunk_size))
  File "/usr/lib/python2.7/dist-packages/gdata/client.py", line 1044, in upload_chunk
    raise error
gdata.client.RequestError: Server responded with: 400, Invalid Request

More output: http://pastebin.com/LZL3qV0N

Any help is appreciated.

1

1 Answers

0
votes

Try using the newer Drive API, its documentation includes Python samples in the reference guide, a Python quickstart and a complete sample application written in Python on App Engine.