Flask API TypeError: Object of type 'Response' is not JSON serializable

后端 未结 4 1651
栀梦
栀梦 2021-02-12 11:41

i have a problem with Python Flask Restful API and data goes to Elasticsearch, when i post a new data with Postman, problem is:

TypeError: Object of type \'Response\' is

相关标签:
4条回答
  • 2021-02-12 12:21
    def post(self):
        some_json=request.get_json()
        return jsonify({'you sent ':some_json})
    

    enough to solve this issue

    0 讨论(0)
  • 2021-02-12 12:34

    Inspired from this bug, here is a shorter way of doing it:

    from flask import jsonify, make_response
    
    def myMethod():
        ....
        return make_response(jsonify(data), 200)
    
    0 讨论(0)
  • 2021-02-12 12:36

    This can be simply done by:

    from flask import jsonify
    def myMethod():
        ....
        response = jsonify(data)
        response.status_code = 200 # or 400 or whatever
        return response
    
    0 讨论(0)
  • 2021-02-12 12:36

    I had a similar problem, the problem is that i was using jsonify twice (jsonify(jsonify({abc:123})))

    0 讨论(0)
提交回复
热议问题