Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python从Google文档中删除资源_Python_Resources_Google Docs Api - Fatal编程技术网

使用Python从Google文档中删除资源

使用Python从Google文档中删除资源,python,resources,google-docs-api,Python,Resources,Google Docs Api,我正在尝试使用以下功能删除Google Docs中的电子表格: def f_DeleteResource(xls_name): """Delete a resource""" client=Auth() for e1 in client.GetResources().entry: e2 = client.GetResource(e1) if xls_name==e2.title.text: client.DeleteResource(e2.resource

我正在尝试使用以下功能删除Google Docs中的电子表格:

def f_DeleteResource(xls_name):
  """Delete a resource"""
  client=Auth()
  for e1 in client.GetResources().entry:
    e2 = client.GetResource(e1)
    if xls_name==e2.title.text:
      client.DeleteResource(e2.resource_id.text,True)
当我更改
client.DeleteResource(p1,p2)
的第一个参数时,我会得到不同的错误:

client.DeleteResource(e2.resource\u id.text,True)

Traceback (most recent call last):
File "C:\xmp\D6GDocsDeleteUpload.py", line 164, in <module> main()
File "C:\xmp\D6GDocsDeleteUpload.py", line 157, in main f_DeleteResource(sys.argv[2])
File "C:\xmp\D6GDocsDeleteUpload.py", line 144, in f_DeleteResource client.DeleteResource(e2.resource_id.text,True)
File "C:\Python27\lib\site-packages\gdata\docs\client.py", line 540, in delete_resource uri = entry.GetEditLink().href
AttributeError: 'str' object has no attribute 'GetEditLink'
Traceback (most recent call last):
File "C:\xmp\D6GDocsDeleteUpload.py", line 164, in <module> main()
File "C:\xmp\D6GDocsDeleteUpload.py", line 157, in main f_DeleteResource(sys.argv[2])
File "C:\xmp\D6GDocsDeleteUpload.py", line 144, in f_DeleteResource client.DeleteResource(e2,True)
File "C:\Python27\lib\site-packages\gdata\docs\client.py", line 543, in delete_resource return super(DocsClient, self).delete(uri, **kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 748, in delete **kwargs)
File "C:\Python27\lib\site-packages\gdata\docs\client.py", line 66, in request return super(DocsClient, self).request(method=method, uri=uri, **kwargs)
File "C:\Python27\lib\site-packages\gdata\client.py", line 319, in request RequestError)
gdata.client.RequestError: Server responded with: 403, <errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>matchHeaderRequired</code><location type='header'>If-Match|If-None-Match</location><internalReason>If-Match or If-None-Match header or entry etag attribute required</internalReason></error></errors>

有人能帮我吗?

这似乎是Google API Python库中的一个bug。我检查了gdata-2.0.16并注意到DeleteResource()函数只使用资源的URL(gdata/docs/client.py行540-543),但后来检查了hasattr(条目_或_uri,'etag')(gdata/client.py行737-741),当然还有字符串值(uri)没有etag属性

您可以使用force关键字参数来解决此问题:

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

client = gdata.docs.client.DocsClient()
client.ClientLogin('xxxxxx@gmail.com', 'xxxxxx', 'XxX')

for doc in client.GetAllResources():
    if doc.title.text == 'qpqpqpqpqpqp':
        client.DeleteResource(doc, force=True)
        break

如果需要,您可以向库维护人员报告错误(如果尚未报告)。

这似乎是Google API Python库中的错误。我检查了gdata-2.0.16并注意到DeleteResource()函数只使用资源的URL(gdata/docs/client.py行540-543),但后来检查了hasattr(条目_或_uri,'etag')(gdata/client.py行737-741),当然还有字符串值(uri)没有etag属性

您可以使用force关键字参数来解决此问题:

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

client = gdata.docs.client.DocsClient()
client.ClientLogin('xxxxxx@gmail.com', 'xxxxxx', 'XxX')

for doc in client.GetAllResources():
    if doc.title.text == 'qpqpqpqpqpqp':
        client.DeleteResource(doc, force=True)
        break

如果需要,您可以向库维护人员报告错误(如果尚未报告)。

此版本已修复此问题:


如果将客户端同步到存储库,则应该能够删除资源,而无需指定“force=True”。

此版本已修复此问题:


如果将客户端同步到存储库,则应该能够删除资源,而无需指定“force=True”。

非常感谢Tupteq!是的,有了这项工作,它就工作了。我在谷歌小组里询问,我从一位开发者那里得到了同样的回答。他更改代码以实现force=True是一个选项:非常感谢Tupteq!是的,有了这项工作,它就工作了。我在谷歌小组里询问,我从一位开发者那里得到了同样的回答。他更改代码以实现强制=真是一个选项: