请求:禁用自动解码 [英] requests: disable auto decoding

查看:16
本文介绍了请求:禁用自动解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否在 requests 1.2.3 版中禁用自动解码功能?

Can you disable the auto decoding feature in requests version 1.2.3?

我已经浏览了文档,但没有找到任何内容,我目前遇到了 gzip 解码错误,想手动调试通过请求传入的数据.

I've looked through the documentation and couldn't find anything, I'm currently experiencing a gzip decode error and want to manually debug the data coming through the request.

推荐答案

您可以像这样访问原始响应:

You can access the raw response like this:

resp = requests.get(url, stream=True)
resp.raw.read()

为了使用 raw,您需要为原始请求设置 stream=True.此外,raw 是一个类文件对象,从 response.content 读取将影响搜索光标.换句话说:如果您已经(尝试)阅读了 response.contentresponse.raw.read() 将返回一个空字符串.

In order to use raw you need to set stream=True for the original request. Also, raw is a file-like object, and reading from response.content will affect the seek cursor. In other words: If you already (tried to) read response.content, response.raw.read() will return an empty string.

请参阅常见问题解答:编码数据快速入门:>请求文档.

See FAQ: Encoded Data and Quickstart: raw response content in the requests documentation.

这篇关于请求:禁用自动解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆