request.get_json() is always NoneType

3.1k views Asked by At

I just created a basic test application with flask:

from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/test", methods=["POST", "GET"])
def test():
    data = request.get_json()
    return str(type(data))

if __name__ == '__main__':
    app.run(debug=True)

The return-Value here is always NoneType! Why doesn't the get_json method my Json-String? I am using Postman to call the url with the json-String. Here is a Screenshot of how i did this:

enter image description here

Can anybody tell what i am doing wrong here? Is the information i gave you enough to figure that out or do you need something else?

1

There are 1 answers

2
AKX On

According to the documentation, get_json() requires the request mimetype (Content-Type) to be application/json.

If the mimetype does not indicate JSON (application/json), this returns None.

Make sure you're sending the request with the Content-type: application/json header.