4
votes

I am trying to create a google spreadsheet in specific folder in google drive with the google drive api. So, far I have written a code to just create a spreadsheet but unfortunately it is not working.

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

# Authorize
client = gdata.docs.client.DocsClient(source='sixact')
client.api_version = "3"
client.ssl = True
client.client_login(EMAIL, PASSWORD, client.source)

# Create our doc
document = gdata.docs.data.Resource(type='spreadsheet', title='Test Report')
newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)
spreadsheet_key = newDocument.GetId().split("%3A")[1]
print "Key = %s" % spreadsheet_key

But this is throwing error in the line newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)

Error Traceback:

Traceback (most recent call last):
  File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\create.py", line 17, in <module>
    newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI)
  File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\gdata\docs\client.py", line 307, in create_resource
    entry, create_uri, desired_class=gdata.docs.data.Resource, **kwargs)
  File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\gdata\client.py", line 686, in post
    entry.to_string(get_xml_version(self.api_version)),
  File "E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\atom\core.py", line 352, in to_string
    tree_string = ElementTree.tostring(self._to_tree(version, encoding))
AttributeError: 'module' object has no attribute 'tostring'

I guess there is something wrong with create_uri. Can I get any help?

1
It's actually throwing an exception on the line ElementTree.tostring within this file: E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\atom\core.py - Is that a line of code that you wrote?Wayne Werner
no... That is not the line of code that I wrote.Santosh Ghimire
Well, ElementTree does have a tostring method, so perhaps you have some funky problem with that. The easiest way to find out is edit that core.py file and add some type of debugging statement before it, e.g. log.debug(ElementTree.__file__) - If it's the file you expect (e.g. C:\Python34\lib\xml\etree\ElementTree.py) then your standard lib may be brokenWayne Werner
What does log.debug(ElementTree.__file__) do?Santosh Ghimire
Whatever you want it to. But I recommend using the logging module to log to a fileWayne Werner

1 Answers

0
votes

The CreateResource method does not take a type argument, only the gdata.docs.data.Resource method takes a type argument. If you would like to look into that go to this link. Refer to the gdata API in order to get a better understanding of CreateResource() and its arguments.

Here is how I set up creating the document:

document = gdata.docs.data.Resource(type='spreadsheet',                                                                                                                        
                                    title= spreadtitle) #spreadtitle = "whatever"                                                                                                                       
document = gd_client.CreateResource(document,
                                    create_uri=gdata.docs.client.RESOURCE_FEED_URI)