我正在深入了解 Python3。当我读到 http web 服务第 14.4 节时,我似乎无法在 python3 shell 中复制以下输出。示例代码如下所示:
from http.client import HTTPConnection
HTTPConnection.debuglevel = 1
from urllib.request import urlopen
response = urlopen('http://diveintopython3.org/examples/feed.xml')
send: b'GET /examples/feed.xml HTTP/1.1
Host: diveintopython3.org
Accept-Encoding: identity
User-Agent: Python-urllib/3.1'
Connection: close
reply: 'HTTP/1.1 200 OK'
…further debugging information omitted…
当我在 ipython3 中输入此命令时,最终命令没有给出任何输出。那么为什么我在示例中没有获得调试信息呢?输入上述代码后,response.debuglevel == 0。我使用的是python3.5.2。
最佳答案
最终命令不应给出任何输出,您可能想要的是:
print(response.read())
关于python - 获取http调试信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39260276/