I know the library requests, but I don't want to use it for different reasons.
So what I am trying is to make a Post request with formdata with curl from Python.
The command looks something like this:
command = "curl --insecure POST --form file1='@path_to_file' --form file2='@path_to_file2' --form config='{"key1": {"key11": "value11", "key12": "value12"}, "key2": {"key21": "value21", "key22": "value22"}' <REST API Adress>"
So if I copy this code manually into the linux terminal it works perfectly fine, but when I am trying to automate that with python subprocess there are backslashs added everywhere in the command. I think that is the reason why it always fails. The code looks like this:
p = Popen([command], cwd=<some path>, stdout=PIPE, stderr=PIPE)
process_output, process_error = p.communicate()
It just fails and prints me a command that looks like this:
command = "curl --insecure POST --form file1=\'@path_to_file\' --form file2=\'@path_to_file2\' --form config=\'{"key1": {"key11": "value11", "key12": "value12"}, "key2": {"key21": "value21", "key22": "value22"}\' <REST API Adress>"
I mean I get it. It is because of the single quotes, but how can I avoid this? Like how can I actually execute the correct command without backslashs?