Flask doesn't print to console

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 future print_function:

import sys

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

See if it helps to print to console.


You can force to flush stdout directly from print:

print('enter getJSONReuslt', flush=True)

This way you don't have to print to sys.stderr (which flushes by default).

The reason for your problem is line buffering. Line buffering makes I/O more efficient with the drawback of not immediately showing prints under some conditions.


By default the level for logging is warning. So you won't see a logging message of level DEBUG. To fix this just enable debug logging with the basicConfig() function of the logging module:

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