等同于python请求PUT文件上传的curl

时间:2018-09-07 17:35:34

标签: python rest python-requests

在python请求中寻找低于curl的值

curl -k --cookie "<cookie>" -H "Content-Type: application/octet-stream" --request PUT 'https://<url>' -F file=@<file path> -F filename=<file name>

尝试以下

upload_file = "/some_file.txt"
HEADERS = {'Content-type': 'application/octet-stream'}
files = {'file': open(upload_file, 'rb')}
cookies = req.cookies

response = session.put(url, files=files, cookies=cookies, 
headers=HEADERS)

请求还可以,但是我在json响应中从服务器收到文件验证错误。看起来文件未按预期上传。相同的文件可以在curl下正常工作。

0 个答案:

没有答案