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 """
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

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