Jeeva
Jeeva

Reputation: 1057

File type not sending with python requests file uploading

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)

RESPONSE FROM SERVER

enter image description here

Upvotes: 0

Views: 82

Answers (1)

Sudheesh Singanamalla
Sudheesh Singanamalla

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

Related Questions