I’m playing around with the Stack Overflow API using Python. I’m trying to decode the gzipped responses that the API gives.
import urllib, gzip
url = urllib
import urllib2
import json
import gzip
import io
url='http://api.stackoverflow.com/1.0/badges/name'
page=urllib2.urlopen(url)
gzip_filehandle=gzip.GzipFile(fileobj=io.BytesIO(page.read()))
json_data=json.loads(gzip_filehandle.read())
print(json_data)
io.BytesIO
is for Python2.6+. For older versions of Python, you could use cStringIO.StringIO
.