curl的文件上传到python请求



我正在尝试将以下curl转换为python请求。此请求上载一个zip文件。

curl -k -i -X POST --form 'session.id=e7a29776-5783-49d7-afa0-b0e688096b5e' --form 'ajax=upload' --form 'file=@myproject.zip;type=application/zip' --form 'project=MyProject' https://localhost:8443/manager

使用curl到python的转换工具-我得到了这个

import requests
files = {
'session.id': (None, 'e7a29776-5783-49d7-afa0-b0e688096b5e'),
'ajax': (None, 'upload'),
'file': ('myproject.zip;type', open('myproject.zip;type', 'rb')),
'project': (None, 'MyProject'),
}
response = requests.post('https://localhost:8443/manager', files=files, verify=False)

但这不起作用

尝试分离数据和文件:

import requests
data = {
"ajax": "upload",
"project": "MyProject",
"session.id": "e7a29776-5783-49d7-afa0-b0e688096b5e",
}
files = {"file": ("myproject.zip", open("myproject.zip", "rb"), "application/zip")}
response = requests.post("https://localhost:8443/manager", data=data, verify=False, files=files)

最新更新