prayagverma / gdata-python-client

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

Can't access contact information anymore #693

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As of 4/1/2014 I'm no longer able to get contacts via the python gdata library.

I'm using version 2.0.18 of the python gdata library distributed with Ubuntu. 
Here is my script:

#!/usr/bin/env python

import gdata.contacts.service

gd_client = gdata.contacts.service.ContactsService()
gd_client.ClientLogin('user', 'password')

query = gdata.contacts.service.ContactsQuery()
query.max_results = 1000 # change for max contacts returned

feed = gd_client.GetContactsFeed(query.ToUri())
print feed

Here is the error that I get:

Traceback (most recent call last):
  File "/home/jpschewe/bin/export-gcontact.py", line 11, in <module>
    feed = gd_client.GetContactsFeed(query.ToUri())
  File "/usr/lib/python2.7/dist-packages/gdata/contacts/service.py", line 104, in GetContactsFeed
    return self.Get(uri, converter=gdata.contacts.ContactsFeedFromString)
  File "/usr/lib/python2.7/dist-packages/gdata/service.py", line 1107, in Get
    'reason': server_response.reason, 'body': result_body}
gdata.service.RequestError: {'status': 301, 'body': 
'<HTML>\n<HEAD>\n<TITLE>Moved Permanently</TITLE>\n</HEAD>\n<BODY 
BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Moved Permanently</H1>\nThe document has 
moved <A 
HREF="https://www.google.com/m8/feeds/contacts/default/full?max-results=1000">he
re</A>.\n</BODY>\n</HTML>\n', 'reason': 'Moved Permanently'}
ERROR: Error getting contacts

Trying to visit the URL in my web browser gives a 404.

Original issue reported on code.google.com by jpsch...@gmail.com on 3 Apr 2014 at 11:58

GoogleCodeExporter commented 9 years ago
I am having this issue as well. From the Google Data Contacts API webpage:

Important: As of March 31, 2014, in order to increase security, the Contacts 
API began redirecting HTTP GET requests to HTTPS, and rejecting POST, PUT, and 
DELETE requests made with HTTP. If your application uses the HTTP protocol, 
please switch to HTTPS. More information.

Anyway to tell the gdata python client to use https?

Original comment by ericmayc...@gmail.com on 3 Apr 2014 at 8:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have discovered a work around for the issue. If you edit line 1088 of 

gdata-2.0.18/src/gdata/services.py

from

    elif server_response.status == 302:

to

    elif server_response.status == 302 or server_response.status == 301:

and then reinstall with

python setup.py install

It will allow the redirect to be followed and for your script to complete.

Original comment by ericmayc...@gmail.com on 3 Apr 2014 at 9:16

GoogleCodeExporter commented 9 years ago
Thank you for that patch. That works nicely even without reinstall. One can 
edit the file in place.

Original comment by jpsch...@gmail.com on 4 Apr 2014 at 1:58

GoogleCodeExporter commented 9 years ago
Same issue, thanks.

Original comment by jzapa...@gmail.com on 4 Apr 2014 at 6:51

GoogleCodeExporter commented 9 years ago
Same issue here.

All working fine again with the solution proposed by Eric.

Thank you very much.

Original comment by sergio.m...@gmail.com on 10 May 2014 at 9:49

GoogleCodeExporter commented 9 years ago
Small note. Release 2.0.18 doesn't seem to be tagged in Mercurial.

Original comment by lya...@gmail.com on 21 Jul 2014 at 7:54

GoogleCodeExporter commented 9 years ago
I've been hit by this problem too.

Applying this patch (a tidier version of the above fix) fixes it.  Could this 
be applied please?  Contacts is unusable without it.

See attached.

Original comment by nic...@gmail.com on 5 Dec 2014 at 10:19

Attachments:

GoogleCodeExporter commented 9 years ago
Isn't it a better patch to just use the https URL?

Original comment by afs...@google.com on 30 Dec 2014 at 9:33

GoogleCodeExporter commented 9 years ago
Yes the https URL would be a better fix.  I'd be happy to test a patch if you 
have one.

Original comment by nic...@gmail.com on 31 Dec 2014 at 4:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I think I went down that road when I first encountered this problem, but could 
not get the https URL to work correctly. 

As stated, if you want to take a stab at it, that would be great . . . but the 
proposed solution has been working flawlessly for me for the last several 
months.

Original comment by ericmayc...@gmail.com on 31 Dec 2014 at 5:03

GoogleCodeExporter commented 9 years ago
I thing I also tried the https path. As I recall it got troublesome with HTTPS 
and the fact that Google redirects. It seems like A good solution though, I 
would like to see a patch.

Original comment by lya...@gmail.com on 1 Jan 2015 at 2:43