Я получаю ответ от сервера с кодировкой 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. - person furas   schedule 07.01.2017Content-Type
- person Nizam Mohamed   schedule 07.01.2017'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
. Ответ:'Content-Type': 'text/html'
- person Mumfordwiz   schedule 07.01.2017requests
распаковывает для вас.content
уже должен быть распакован, и вы не можете распаковать его снова. - person tdelaney   schedule 07.01.2017print r.content
иprint r.text
- второй должен дать уже декодированный с использованиемutf-8
- person furas   schedule 07.01.2017r.text
возвращает декодированные строки, аcontent
— это простоbytes
. - person tdelaney   schedule 07.01.2017requests
док. - person Nizam Mohamed   schedule 07.01.2017r.raw
. - person Nizam Mohamed   schedule 07.01.2017