Flask POST request is causing server to crash

First what you want to do is enable debug mode so Flask will actually tell you what the error is. (And you get the added benefit of flask reloading every time you modify your code!)

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

Then we find out our error:

TypeError: 'dict' object is not callable

You’re returning request.json, which is a dictionary. You need to convert it into a string first. It’s pretty easy to do:

def api_response():
    from flask import jsonify
    if request.method == 'POST':
        return jsonify(**request.json)

There you are! 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)