4
votes

I have a python script that takes a generated CSV and uploads it to Google Docs. It can upload it just fine, put I cannot seem to get it to replace the data, it returns an error I cannot find reference to.

Le Code:

import gdata.auth
import gdata.docs
import gdata.docs.service
import gdata.docs.data
import gdata.docs.client


email = '[email protected]'
CONSUMER_KEY='domain.com'
CONSUMER_SECRET='blah54545blah'


ms_client = gdata.docs.client.DocsClient('Domain_Doc_Upload')
ms_client.auth_token = gdata.gauth.TwoLeggedOAuthHmacToken(CONSUMER_KEY, CONSUMER_SECRET, email)

url = 'http://docs.google.com/feeds/documents/private/full/sd01blahgarbage'

ms = gdata.data.MediaSource(file_path="C:\\people.csv", content_type='text/csv')
csv_entry2 = ms_client.Update(url, ms)

It returns:

Traceback (most recent call last):
  File "so_test.py", line 19, in <module>
    csv_entry2 = ms_client.Update(ms, url)
  File "build\bdist.win-amd64\egg\gdata\client.py", line 717, in update
AttributeError: 'MediaSource' object has no attribute 'to_string'

I cannot find anything about the 'to_string' attribute, so I am lost on the trace. ANy help, much appreciated.

1
Try this ms = gdata.data.MediaSource(file_path="C:\\people.csv", content_type='text/csv'). Take a look here tinyurl.com/88grdk6 ` - RanRag
Did not notice that, but, unfortunately, the same error. - Kevin
This is the correct way updated_entry = client.Update(entry, media_source=ms). So, try this csv_entry2 = ms_client.Update(url,ms) - RanRag
I would suggest you to take a look at official docs first. - RanRag
@RanRag it is now returning str object has no attribute 'to_string', so I get the feeling I am passing the wrong object to the client, I did look at the docs, I am still having issues, thats why I came here. - Kevin

1 Answers

1
votes

I took a look at the docs and it looks like the Update method takes (entry, ms) where entry needs to be a gdata.docs.data.DocsEntry object. You should be able to get the DocsEntry object by getting a feed from your client.

feed = client.GetDocList()