votes up 3

Failed to decode JSON object: (e)

Package:
flask
github stars 56479
Exception Class:
BadRequest

Raise code

        ):
            from .debughelpers import attach_enctype_error_multidict

            attach_enctype_error_multidict(self)

    def on_json_loading_failed(self, e: Exception) -> "te.NoReturn":
        if current_app and current_app.debug:
            raise BadRequest(f"Failed to decode JSON object: {e}")

        raise BadRequest()


class Response(ResponseBase):
    """The response object that is used by default in Flask.  Works like the
    response object from Werkzeug but is set to have an HTML mimetype by """
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 0 votes down

Summary: Need to send valid to the post endpoint

Code to run Flask API:

from flask import Flask, request
app = Flask(__name__)

@app.route('/post',methods = ['POST'])
def post():
 if request.method == 'POST':
 return request.get_json()


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

Code to reproduce (WRONG):

curl -X POST http://127.0.0.1:5000/post -H "Content-Type: application/json" -d '{"key", "value"}' # Invalid json

Working version (Fixed):

curl -X POST http://127.0.0.1:5000/post -H "Content-Type: application/json" -d '{"key": "value"}' # <--- FIX: change to valid json

Jun 03, 2021 phoang88 answer
phoang88 615

Add a possible fix

Please authorize to post fix