Solve the problem of flag error valueerror: View function did not return a response

Today, we use Python to implement the restful interface of Flask, and then call it wrong.

ValueError: View function did not return a response

The code is as follows:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

      param = request.json

      print(param)

The reason for the error is that the restful interface of flag must have a return value.

Therefore, modify the code to add the return value:

Add: return XXXX

For example:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

    try:

        if not request.json:

            return jsonify({'code': -1, 'message': 'request is not json'})

        param = request.json

        return jsonify({'code': 0, 'status': 'running'})

    except Exception as e:

        print(e)

        return jsonify({'code': -1, 'error_message':e})

 

Read More: