Reputation: 1057
I am trying to upload a file using python requests, but when I try to post the file the file type not there.
import requests, json, time
session = requests.Session()
with open("./error2.jpg", 'rb') as f:
res = session.post("http://rayinrice.com/upload/", files={"files": f})
print("Status Code: *" + str(res.status_code))
print("\nContent:\n" + res.content)
Upvotes: 0
Views: 82
Reputation: 2297
You can use the files
parameter in request.post()
. You can do this by doing the following.
files = {'files': open('error2.jpg','rb')}
r = requests.post(url, files=files)
Upvotes: 1