carolinux / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
0 stars 1 forks source link

Using Python and gdata cannot delete a contact from my own account #525

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a contact
2. Use gdata to get feed for a particular contact group. This works fine.
self.feed = self.gd_client.GetContactsFeed(query.ToUri())
feed = []
for i, entry in enumerate(self.feed.entry):
    for group in entry.group_membership_info:
        if group.href == group_id:
            feed.append(entry)
            continue
return feed
3. Then try to delete contacts listed in that feed. No bueno.
error_msg = ''
for entry in feed:
    try:
        self.gd_client.DeleteContact(entry.GetEditLink().href)
    except Exception, err:
        error_msg = str(err)
return error_msg

This returns a error_msg of "{'status': 403, 'body': 'If-Match or If-None-Match 
header or entry etag attribute required', 'reason': 'Forbidden'}"

4. So I change the DeleteContact parameter list to: 
    ...DeleteContact(contact_entry.GetEditLink().href, extra_headers={'If-Match': '*'})

Still no bueno. 

5. So I use a debugger to trace into gdata code and I find that in the 
"C:\Python25\Lib\site-packages\gdata\contacts\service.py" file, it has a 
parameter for extra_headers but it does nothing with that parameter. So on line 
181 I added extra_headers=extra_headers, to the parameter list as follows:
    return self.Delete(self._CleanUri(edit_uri), extra_headers=extra_headers,
                       url_params=url_params, escape_params=escape_params)

Viola, it now works. The contact is deleted and no exception is thrown. 

What is the expected output? What do you see instead?
I expected the contacts to be deleted without having to modify gdata code. 
Instead I see an exception thrown unless I change line 181.  

What version of the product are you using?
gdata-2.0.14

Please provide any additional information below.
Is it a bug in your code or am I missing something? 

Original issue reported on code.google.com by bob...@invtools.com on 30 Jun 2011 at 3:26

GoogleCodeExporter commented 9 years ago
Hello,

Please use the new client/data modules instead of the service module as it is 
not maintain anymore. Using a gdata.contacts.client.ContactsClient should 
resolve the issue as the Etag will be retrieve from the 
gdata.contacts.data.ContactEntry object.

Best,
Alain

Original comment by ala...@google.com on 30 Jun 2011 at 6:06