def decode(page):
    encoding = page.info().get('Content-Encoding')
if encoding in ('gzip', 'x-gzip', 'deflate'):
    content = page.read()
if encoding == 'deflate':
    data = StringIO.StringIO(zlib.decompress(content))
else:
    data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(content))
page = data.read()
return page
Url open encoding