[英]How to view the HTTP headers, response code and html content using urllib3 in Python?
我对使用 urllib3 检索响应代码、正文和 HTTP 标头感兴趣。 我之前编写的代码是在 Python 2 中编写的,现在我必须为 Python 3 重写它。
import urllib3
http = urllib3.PoolManager();
response = http.request('GET', 'http://192.168.43.131:8000')
print(response)
我尝试了不同的来源,但有人能指出我正确的方向吗?
我想你的意思是:
import json
import urllib3
http = urllib3.PoolManager()
response = http.request('GET', 'http://192.168.43.131:8000')
print(response.status)
print(response.headers)
print(json.loads(response.data.decode('utf-8'))) # body
文档: https : //urllib3.readthedocs.io/en/latest/user-guide.html
我想你已经找到了?
https://urllib3.readthedocs.io/en/latest/user-guide.html#response-content
这表明您可以获取状态代码,例如,
print(response.status)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.