python - 获取http调试信息

标签 python python-3.x urllib http.client

我正在深入了解 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/

相关文章:

python - 以数据框行名称作为图例的 matplotlib 条形图

python - Pandas:连接数据框中的两列(不创建两列)

python-3.x - 我如何找出哪个人住的最多晚数?姓名和总天数?

python - 如何使用 PYTHON 的 mysql-connector 将 MySQL 数据库导出为 json?

python - 在 Python 中,如何使用 urllib 来查看一个网站是 404 还是 200?

python - 将文件 IO 从 urllib 重写为 csvreader

python - 为什么python中没有list.clear()方法?

Python argparse - 强制参数 - 位置或可选

python - 计算条目一中另一个列表中的列表中的单词

python - 使用 urllib 和 Python 3.3 进行简单的 POST