0

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?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
lxg95
  • 553
  • 2
  • 8
  • 28

1 Answers1

1

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.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • ah ok, i guess that is it, but where do i set this in PostMan? I see the content-type is ```text/html; charset=utf-8``` but i can't change that value – lxg95 Sep 25 '21 at 13:40
  • See [Postman's docs](https://learning.postman.com/docs/sending-requests/requests/#sending-body-data): "If you use raw mode for your body data, Postman will set a header based on the type you select (e.g. text, json). If you manually select a Content-Type header, that value will take precedence over what Postman sets." You seem to have `text` selected in your screenshot (right next to the "GraphQL" radio button). – AKX Sep 25 '21 at 13:41