【问题标题】:create google spreadsheet in specific folder in drive | Google drive api在驱动器的特定文件夹中创建 google 电子表格 |谷歌驱动API
【发布时间】: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 - 这是你写的那一行代码吗?
  • 不...那不是我写的那行代码。
  • 好吧,ElementTree does 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


【解决方案1】:

CreateResource 方法不接受类型参数,只有 gdata.docs.data.Resource 方法接受类型参数。如果您想对此进行调查,请访问this link。请参阅gdata API 以更好地了解 CreateResource() 及其参数。

这是我如何设置创建文档:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多