urllib3调试请求标头

问题描述 投票:2回答:1

我正在使用urllib3,我想查看发送的标头。

我在文档中找到了这个,但是它不打印标题:

urllib3.add_stderr_logger(1)

有什么办法吗?

python-3.x urllib3
1个回答
3
投票

目前,实现真正冗长的日志记录(包括在urllib3中发送的标头的最佳方法是覆盖httplib中的默认值(内部使用)。

对于Python 3:

# You'll need to do this before urllib3 creates any http connection objects
import http.client
http.client.HTTPConnection.debuglevel = 5

# Now you can use urllib3 as normal
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', ...)

在Python 2中,HTTPConnection对象位于httplib模块下。

这将打开所有使用httplib的详细日志记录。请注意,这并未使用httplib的已记录API,但是它正在修补HTTPConnection类的默认值。

目标是为这类事情添加更好的urllib3-native日志记录,但尚未实现。相关问题:https://github.com/shazow/urllib3/issues/107

© www.soinside.com 2019 - 2024. All rights reserved.