I am trying to convert the following curl to a python request. This request uploads a zip file.
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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.