[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

flask problem

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():
    resp = Response(json.dumps({'status':'Good'}),  status=200,  mimetype='application/json')
    return resp
if __name__ == '__main__':
    app.run(debug=True, host='', port=8002)

And here is the simple client:

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

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

 * Running on (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.