flask problem

jaybraun2.0 at gmail.com jaybraun2.0 at gmail.com
Sat Feb 16 23:53:00 EST 2019


I have used flask before with no problem.  Now I am getting very mysterious results, which I have reduced to a very small test case.

Here is a flask server, in Python 3, which waits for a message on port 8002 (the port is open):


from flask import Flask, Response
import json
app = Flask(__name__)
@app.route('/jay', methods=['PUT'])
def analyze():
    print("hello")
    resp = Response(json.dumps({'status':'Good'}),  status=200,  mimetype='application/json')
    return resp
if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=8002)


And here is the simple client:


import requests
r = requests.put('http://13.57.96.64:8002/jay', data='{ "test": "Jay" }', headers={"Content-Type": "application/json"}, verify=False)
print(r)

I bring up the server, and as expected, it outputs:

 * Running on http://0.0.0.0:8002/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 292-073-960

and waits.  Then I run the client and see:

<Response [200]>

So the connection is fine.  But the server does not print to the terminal.  (In my actual application, it needs to do much more, but does nothing.)  Without the server running, the client fails to make a connection, as expected.  So the only effect of the server is to create the REST endpoint -- but it does not execute the logic that a message is supposed to trigger.

Hopefully, another pair of eyes will see the problem.  Thanks.

Jay




More information about the Python-list mailing list