Get json from request flask [duplicate] Get json from request flask [duplicate] flask flask

Get json from request flask [duplicate]


You are sending form encoded data, not JSON. Just setting the content-type doesn't turn your request into JSON. Use json= to send JSON data.

response = requests.post(url, json={"user": user,"pass": password})

Retrieve the data in Flask with:

data = request.get_json()


I tried executing the same code that you have posted and I was able to fetch values for username and password instead of None.

enter image description here


My initial guess is that since you aren't setting the Content-Type header in your request Flask doesn't understand that it should be able to parse the data. Try adding Content-Type header with the value application/json and see if that gets you where you want.

Another thing to note is when I hit my login page the browser sets the Content-Type header to application/x-www-form-urlencoded and encodes the data as user=asdf&passwd=asdf