Well, I answer my question, since there is no other answer available.
Yes, I got the result, finally, for more information about my work around the question, the following information may help.
1. What does boundary do in a multipart/form-data request?
In fact, to separate different parts of the data there is such a request, we use a separator, here we call boundary to separate the form data.
These parts can be a field value (plain text) or load the contents of a file.
2. First we put the boundary line in the request header.
To declare that the request is accepted in the format mulitipart/form-data , we first select a special line called boundary and put it in the request header:
Content-Type: multipart/form-data; boundary=FORM-BOUNDARY
When we see that here we select the FORM-BOUNDARY boundary line, we can select any desired line.
In most cases, we can choose a long, random string to prevent a collision.
3. Use the selected border in the request body.
In the request body (payload), we share data with a boundary delimiter, for example:
--FORM-BOUNDARY Content-Disposition: form-data; name="template"; filename=".xls" Content-Type: application/vnd.ms-excel A654ADE5^%^#%@% $@ (BINARY DATA IN THIS SECTION) --FORM-BOUNDARY Content-Disposition: form-data; name="username" admin --FORM-BOUNDARY Content-Disposition: form-data; name="password" admin_password --FORM-BOUNDARY--
Upon seeing this, we will start one part of the form with a separator, after boundary after one character -- .
Then in this part of the form we export the title to declare the type of content and the name of this field.
Then one blank line is required.
Then we export the value (data) of this part of the form.
After all parts of the form, we completed the request body with a separator, with a boundary between two characters -- .
4. So, what does mimetools.choose_boundary ??
In fact, this function (deprecated since py3) generates a random border with the specified format: https://docs.python.org/2.7/library/mimetools.html?highlight=choose_boundary#mimetools.choose_boundary
Format:
'hostipaddr.uid.pid.timestamp.random'
Just so simple.
If we insist on getting the same result,
- we ourselves can write the functionality.
- Or call the
email.generator function of the _make_boundary() module.
But really, to make it work, you donβt have to do it, just create a random string to replace it!