【发布时间】:2021-02-11 06:28:16
【问题描述】:
我可以使用 python 中的 urllib3 库成功发出多部分发布请求。但是如何在发出 POST 请求时打印请求正文?
在 python 请求库:我们有如下选项: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'
【问题讨论】:
标签: python json python-3.x python-requests urllib3