4

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?

Santosh Ghimire
  • 3,087
  • 8
  • 35
  • 63
  • 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 Dec 09 '13 at 14:43
  • no... That is not the line of code that I wrote. – Santosh Ghimire Dec 09 '13 at 14:44
  • Well, `ElementTree` [*does* have a tostring](http://docs.python.org/2/library/xml.etree.elementtree.html#xml.etree.ElementTree.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 broken – Wayne Werner Dec 09 '13 at 14:51
  • What does `log.debug(ElementTree.__file__)` do? – Santosh Ghimire Dec 09 '13 at 15:14
  • Whatever you want it to. But I recommend using the `logging` module to [log to a file](http://docs.python.org/2/howto/logging.html#logging-to-a-file) – Wayne Werner Dec 09 '13 at 15:17
  • I added the statement in core.py before the line throwing error. But no thing is happening. – Santosh Ghimire Dec 09 '13 at 15:21
  • Did you look at the log file? – Wayne Werner Dec 09 '13 at 15:21
  • Where is the log file created? – Santosh Ghimire Dec 09 '13 at 15:23
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42793/discussion-between-wayne-werner-and-santosh-ghimire) – Wayne Werner Dec 09 '13 at 15:27

1 Answers1

0

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) 
davzaman
  • 823
  • 2
  • 10
  • 20