DeleteResource from Google Docs with Python

瀏覽次數:78 次
跳到第一則未讀訊息

Javier Pimienta

未讀,
2012年3月30日 清晨6:09:182012/3/30
收件者: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

未讀,
2012年3月30日 中午12:56:272012/3/30
收件者: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

未讀,
2012年3月30日 下午2:38:142012/3/30
收件者: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

未讀,
2012年3月30日 下午3:40:412012/3/30
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息