如何在urllib3 python中打印请求体



我可以使用urllib3库在python中成功地制作post multipart请求。然而,如何打印请求体时,POST请求?

Inpython requests library:我们有这样的选项:print(response.request.body)

代码是这样的:

http = urllib3.PoolManager()

path_bdl = os.path.dirname(__file__) + '/some_bin_file.xyz'
content_json = os.path.dirname(__file__) + '/some_json.json'

with open(path_, 'rb') as fp:
binary_data = fp.read()
with open(content_json, 'r') as j:
json_data1 = j.read()
url = "//myurl"
headers = {}  # dictionary
response = http.request(
'POST',
url,
fields={
"abc": (content_json, json_data1, "application/json"),
"bbb": (path_, binary_data, "xyz_Content_type")
},
headers=headers
)
print('n StatusCode: ', response.status)
print(response.headers)
print(response.request) >>>>>>>>>>>> HTTPResponse has no attribute 'request'

From the docs:

HTTPResponse对象提供状态、数据和报头属性

尝试使用response.data读取响应的数据部分。

最新更新