【发布时间】:2013-12-09 14:38:17
【问题描述】:
我正在尝试使用 google drive api 在 google drive 的特定文件夹中创建一个 google 电子表格。所以,到目前为止,我已经编写了一个代码来创建一个电子表格,但不幸的是它不起作用。
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
但这会在newDocument = client.CreateResource(document, type = "spreadsheet", create_uri=gdata.docs.client.RESOURCE_FEED_URI) 行中抛出错误
错误回溯:
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'
我猜想 create_uri 有问题。我能得到任何帮助吗?
【问题讨论】:
-
它实际上是在这个文件中的
ElementTree.tostring行上抛出了一个异常:E:\coding\FL\ongoing jobs\Expert python-django\test\sixact\atom\core.py- 这是你写的那一行代码吗? -
不...那不是我写的那行代码。
-
好吧,
ElementTreedoes have a tostring 方法,所以也许你有一些时髦的问题。最简单的查找方法是编辑core.py文件并在其前面添加某种类型的调试语句,例如log.debug(ElementTree.__file__)- 如果是您期望的文件(例如C:\Python34\lib\xml\etree\ElementTree.py),那么您的标准库可能已损坏 -
log.debug(ElementTree.__file__)是做什么的? -
随心所欲。但我建议使用
logging模块到log to a file
标签: python google-drive-api gdata google-drive-realtime-api