[英]curl with file upload to python request
I am trying to convert the following curl to a python request.我正在尝试将以下 curl 转换为 python 请求。 This request uploads a zip file.此请求上传一个 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
Using curl to python convertor tool - I got this使用 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)
But this doesn't work但这不起作用
Try separating data and files:尝试分离数据和文件:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.