How to intentionally cause a 400 Bad Request in Python/Flask?

后端 未结 4 2330
广开言路
广开言路 2021-02-19 00:18

A consumer of my REST API says that on occasion I am returning a 400 Bad Request - The request sent by the client was syntactically incorrect. error.

4条回答
  •  日久生厌
    2021-02-19 01:10

    Also, You can use jsonify

    from flask import jsonify
    
    class SomeView(MethodView):
        def post(self, *args, **kwargs):
            if "csv_file" not in request.files:
                return jsonify({'errors': 'No csv_file key in request.files.'}), 400
    

提交回复
热议问题