Checkbox does not print to console

I am new to flask and I am trying to add print information to debug server side code. When running the app with a flag with debug = True, I cannot get any printable information to the console

I tried to use the recording but no luck. So, how to debug the console flask.

@app.route('/getJSONResult', methods=['GET', 'POST'])
def getJSONResult():

    if request.method == 'POST':
        uut = request.form['uut']
        notes = request.form['notes']
        temperature = request.form['temperature']

        logging.info("enter getJSONReuslt")
        print('enter getJSONReuslt')
        filter_by_query = {k: v for k, v in {
            'uut': uut, 'notes': notes, 'temperature': temperature}.items() if v != ""}
        s = session.query(UUT_TEST_INFO).filter_by(**filter_by_query).first()
        return jsonify(s.serialize)

if __name__ == '__main__':
    app.secret_key = ''.join(random.choice(
        string.ascii_uppercase + string.digits) for x in range(32))
    app.debug = True
    app.run(host='127.0.0.1', port=5000)


> 127.0.0.1 - - [07/Jun/2017 15:20:48] "GET /qyer HTTP/1.1" 200 -
> 127.0.0.1 - - [07/Jun/2017 15:20:48] "GET /static/css/bootstrap.min.css HTTP/1.1" 200 -
> 127.0.0.1 - - [07/Jun/2017 15:20:48] "GET /static/js/bootstrap.min.js HTTP/1.1" 200 -
> 127.0.0.1 - - [07/Jun/2017 15:20:51] "GET /static/css/bootstrap.min.css.map HTTP/1.1" 200 -
> 127.0.0.1 - - [07/Jun/2017 15:21:58] "POST /getJSONResult HTTP/1.1" 500 -

      

I fixed a 500 server side error, now ask for code 200 and the console will show the following information

$ python project.py
INFO:werkzeug: * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger pin code: 158-624-607
INFO:werkzeug:127.0.0.1 - - [08/Jun/2017 11:33:33] "GET /qyer HTTP/1.1" 200 -
INFO:root:Enter getJSONResult
INFO:werkzeug:127.0.0.1 - - [08/Jun/2017 11:33:43] "POST /getJSONResult HTTP/1.1" 200 -

      

Still no information from print command

+16


source to share


4 answers


Try this and see if it helps:

For python2:

from __future__ import print_function
import sys

print('This is error output', file=sys.stderr)
print('This is standard output', file=sys.stdout)

      



For python3, you don't need to import from the future print_function:

import sys

print('This is error output', file=sys.stderr)
print('This is standard output', file=sys.stdout)

      

See if this helps for printing to the console.

+27


source


By default, the logging level is warning. Thus, you will not see the level registration message DEBUG

. To fix this, just enable debug logging using basicConfig()

the logger function :



import logging
logging.basicConfig(level=logging.DEBUG)

      

+10


source


There was the same printing problem. Using sys.stdout.flush()

after print

solved the problem.

+1


source


You can forcefully flush standard output from printing:

print('enter getJSONReuslt', flush=True)

      

This way you don't have to type in sys.stderr

(which is reset by default).

Linear buffering is causing your problem. Linear buffering makes I / O more efficient, with the disadvantage of immediately displaying fingerprints under certain conditions.

0


source







All Articles