我正在使用urllib3,我想查看发送的标头。
我在文档中找到了这个,但是它不打印标题:
urllib3.add_stderr_logger(1)
有什么办法吗?
目前,实现真正冗长的日志记录(包括在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