It works fine with gzip (gzip and zlib have the same compression, but with different headers / "wrapping. Your error contains this information in the message).
import gzip import urllib.request request = urllib.request.Request( "http://google.com/search?q=foo", headers={ "Accept-Encoding": "gzip", "User-Agent": "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11", }) response = urllib.request.urlopen(request) gzipFile = gzip.GzipFile(fileobj=response) gzipFile.read()
u0b34a0f6ae
source share