【发布时间】:2017-01-07 17:51:07
【问题描述】:
我收到来自使用 gzip 编码的服务器的响应, 但我不知道如何解码。
我尝试使用 zlib 模块,但出现错误:
zlib.error: Error -3 while decompressing data: incorrect header check
这是我的要求:
r = requests.post(url=url,headers=headers,auth=auth,data=data)
print r.status_code
print r.headers
print zlib.decompress(r.content)
我得到的打印是:
200
{'Content-Length': '1232', 'Content-Encoding': 'gzip', 'Accept-Ranges': 'bytes', 'X-Powered-By': 'PHP/5.5.38', 'Vary': 'Accept-Encoding', ...
错误:
Traceback (most recent call last):
File "C:/testing.py", line 27, in <module>
print zlib.decompress(r.content)
zlib.error: Error -3 while decompressing data: incorrect header check
【问题讨论】:
-
requests应该为您提供未压缩的内容,因此您不必使用 zlib。 -
发帖
Content-Type -
请求:
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'。回复:'Content-Type': 'text/html' -
requests为您解压。content应该已经解压了,不能再解压了。 -
好的.. 我去看看。我确实收到了文本,但其中一些似乎被压缩了。你可能是对的
标签: python gzip httpresponse zlib decoding