[Developers] metaweb.py- when readservice returns a gzip'd response
Bob Skinner
bob_skinner at yahoo.com
Fri Jul 25 23:00:25 UTC 2008
Hi,
I'm just getting started with the python interface using the metaweb.py example from Appendix B. (Using python 2.4)
Using the .login or .read methods right "out of the box" always returned a
"ValueError: No JSON object could be decoded" error in the simplejson.load call.
The reason was the response was gzip encoded, I had to change the read method from:
f = urllib2.urlopen(req) # Open the URL
response = simplejson.load(f)
to:
f = urllib2.urlopen(req) # Open the URL
if 'Content-Encoding' in f.info() and f.info()['Content-Encoding'] == 'gzip':
buf = cStringIO.StringIO(f.read())
gbuf = gzip.GzipFile(mode='rb', fileobj=buf)
response = simplejson.load(gbuf) # Parse JSON response to an object
else:
response = simplejson.load(f)
I couldn't find anything on the documentation or in the developer mailing list archives to this end. Is there some better way of handling this that I should be using?
best regards,
Bob Skinner
p.s. I think you guys are on to something HUGE with Freebase. Your implementation/api looks stellar. I'm a big fan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freebase.com/pipermail/developers/attachments/20080725/72b46dd1/attachment.htm
More information about the Developers
mailing list