How to send a multipart/form-data
with requests in python? How to send a file, I understand, but how to send the form data by this method can not understand.
You need to use the name
attribute of the upload file that is in the HTML of the site. Example:
autocomplete="off" name="image">
You see name="image">
? You can find it in the HTML of a site for uploading the file. You need to use it to upload the file with Multipart/form-data
script:
import requests
site = 'https://prnt.sc/upload.php' # the site where you upload the file
filename = 'image.jpg' # name example
Here, in the place of image, add the name of the upload file in HTML
up = {'image':(filename, open(filename, 'rb'), "multipart/form-data")}
If the upload requires to click the button for upload, you can use like that:
data = {
"Button" : "Submit",
}
Then start the request
request = requests.post(site, files=up, data=data)
And done, file uploaded succesfully