简体   繁体   中英

cannot return response to browser flask

I have a web service which should be stay listening for a new message for real-time chat, the problem that I cannot return it's response nor a simple text because this part of code:

    # Print every message the current user would receive
     # This is a blocking call that will run forever
    (client.call_on_each_message(debug))

stay listening forever so I implement an actual function to return the responses but my code ends with printing test without passing to return the message, this line of code:

    return jsonify((str(msg))), 200

what shall I do to return the response to the browser

    @app.route('/listenrealtime', methods=['GET'])
    def listenrealtime():
         def debug(msg): 
             msg: lambda msg: (str(msg))
             print('test')
             print(msg)
             return jsonify((str(msg))), 200
       
         # Pass the path to your zuliprc file here.
         client = zulip.Client(config_file="~/zuliprc")
     
         # Print every message the current user would receive
         # This is a blocking call that will run forever
         (client.call_on_each_message(debug))
     
         # Print every event relevant to the user
         # This is a blocking call that will run forever
         return "Some text"

It fails to return because of a misplaced parenthesis:

return jsonify(((str(msg)), 200)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM