tôi đã mong đợi này để làm việc:Cách tốt nhất để giải nén đáp ứng máy chủ gzip'ed bằng Python 3 là gì?
>>> import urllib.request as r
>>> import zlib
>>> r.urlopen(r.Request("http://google.com/search?q=foo", headers={"User-Agent": "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11", "Accept-Encoding": "gzip"})).read()
b'af0\r\n\x1f\x8b\x08...(long binary string)'
>>> zlib.decompress(_)
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
zlib.decompress(x)
zlib.error: Error -3 while decompressing data: incorrect header check
Nhưng nó không. Lặn sâu vào Python uses StringIO trong ví dụ này, nhưng điều đó dường như bị thiếu từ Python 3. Cách làm đúng đắn là gì?