Skip to content Skip to sidebar Skip to footer

Status 500 Using Requests In Python

So I am working on sending images to an url. And I planned to use Python to make the POST requests. My code looks like this: import requests headers = {'User-Agent': 'Mozilla/5.0

Solution 1:

The problem is that we have to send the data to a post request in the JSON format but we are sending it as a dictionary which makes the request a bad request. So the best approach known to me is to convert the data to JSON format (this might be because of the parsing that takes place at the server side)

import json
data = data={'file':open('1-watermarked-page.PNG', 'rb')}
response = request.post("url",json.dumps(data))
# json.dumps(data) converts data to json format

This worked for me, let me know if it worked for you

Post a Comment for "Status 500 Using Requests In Python"