DeleteResource from Google Docs with Python

78 views
Skip to first unread message

Javier Pimienta

unread,
Mar 30, 2012, 6:09:18 AM3/30/12
to google-docum...@googlegroups.com
I am trying to delete a spreadsheet in Google Docs with this function:

    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)

And I obtain different errors when I change the first parameter of client.DeleteResource(p1,p2):

client.DeleteResource(e2.resource_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'

client.DeleteResource(e2,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,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>

Anyone can help me?

Thanks a lot!!

Alain Vongsouvanh

unread,
Mar 30, 2012, 12:56:27 PM3/30/12
to google-docum...@googlegroups.com
Hello Javier,

The client library currently doesn't let you specify the Etag when sending a Delete request.
As a work around, you can use:

  client.DeleteResource(e2, True, force=True)

This will set the If-Match header as "If-Match: *" to tell the API that your client application wants to delete this resource regardless of other applications' changes.

Best,
Alain
--
Alain Vongsouvanh | Developer Programs Engineer

Alain Vongsouvanh

unread,
Mar 30, 2012, 2:38:14 PM3/30/12
to google-docum...@googlegroups.com
Hello Javier,

This should be fixed as of:

You don't need to specify the force=True argument anymore (unless you want to :) ).

Best,
Alain

sit...@gmail.com

unread,
Mar 30, 2012, 3:40:41 PM3/30/12
to google-docum...@googlegroups.com
Hello Alain,

Thank you so much! It works now! Great! :)))

I have been working in this issue all the day.

Javier
Enviado desde mi dispositivo BlackBerry® de Orange.

From: Alain Vongsouvanh <ala...@google.com>
Date: Fri, 30 Mar 2012 11:38:14 -0700
Subject: Re: DeleteResource from Google Docs with Python
Reply all
Reply to author
Forward
0 new messages