I think the most ideal way would be this:
import requests
url = "{YOUR URL}"
payload={}
files=[
('file',('filename',open('/pathtofile/filename','rb'),'application/{FILE_TYPE}'))
]
headers = {
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
For multiple variables within your filepath, you can simply concat two or more strings, just define your variables and concat them in the filepath and you'd be good to go.
Like:
folder = "abc"
filepath = "C:/Users/xyz/" + abc
You can concat as many strings as you'd like. And therefore, inside the files
list, you can simply replace the string inside open() function with your filepath variable, so your files list would become:
files=[
('file',('filename',open(filepath,'rb'),'application/{FILE_TYPE}'))
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…