Hi, you have to manually generate the body of a http post request.
Um, so, an http post request opens a socket with the remote server and just sends a series of lines of text with \r\n at the end.
The first number of these are called headers. The requests module is just generating these headers for you versus you having to supply them.
Then the body typically contains more information or more headers. Which are just \r\n lines. The separation of the headers and body is specified by a blank line between the two.
When you specified the files argument… that typically gets parsed by the library and turned into a sequence of headers and data for you. However, we have no support for that. So, you have to manually do it yourself.
E.g. see this: What should a Multipart HTTP request with multiple files look like? - Stack Overflow
That is what requests is actually generating for you under the hood.
So, the if you have to generate it yourself and make the body part yourself then you need to make the:
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile1"; filename="r.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile2"; filename="g.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Disposition: form-data; name="datafile3"; filename="b.gif"
Content-Type: image/gif
GIF87a.............,...........D..;
--2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f--
Part of the file which is the data payload. However, in order to generate a mulit-part http form request you have to use this header for the content:
Content-Type: multipart/form-data; boundary=2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
Content-Length: 514
…
Notes: The “GIF87a…,…D…;” is the raw file data. So, basically, you write out the header:
Content-Disposition: form-data; name="datafile2"; filename="g.gif"\r\n
Content-Type: image/gif\r\n\r\n
And then you write out the raw data of the file.
And then you add the boundary:
–2a8ae6ad-f4ad-4d9a-a92c-6d217011fe0f
…
The boundary is a random string that should not appear in the raw data that you specify in the “multipart/form-data;” header.
…
Yes, this is low-level internet programming. However, if you know what format the remote server expects then everything will work.