DeleteResource from Google Docs with Python

耗尽温柔 提交于 2019-12-08 18:29:24

It seems to be a bug in Google API Python library. I checked gdata-2.0.16 and noticed that DeleteResource() function uses only URL of the resource (gdata/docs/client.py lines 540-543), but later checks for hasattr(entry_or_uri, 'etag') (gdata/client.py lines 737-741) and of course string value (uri) doesn't have etag attribute.

You may work around it using force keyword argument:

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

If you want you may report an error to library maintainers (if it isn't already reported).

This issue has been fixed in this revision: http://code.google.com/p/gdata-python-client/source/detail?r=f98fff494fb89fca12deede00c3567dd589e5f97

If you sync you client to the repository, you should be able to delete a resource without having to specify 'force=True'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!