0

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 '[email protected];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

asked Nov 16, 2021 at 6:55

1 Answer 1

2

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)
answered Nov 16, 2021 at 7:49
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.