您无需在
.read()这里使用,只需直接流对象。您确实需要显式设置Content-
Type标头;
curl使用时执行此操作,
--data但
requests不执行以下操作:
with open('data','rb') as payload: headers = {'content-type': 'application/x-www-form-urlenpred'} r = requests.post('https://IP_ADDRESS/rest/rest/2', auth=('userid', 'password'),data=payload, verify=False, headers=headers)我已经使用了打开文件对象作为上下文管理器,以便当块退出时(例如发生异常或
requests.post()成功返回),它也会自动为您关闭。



