Python – wsgi and python print statements

mod-wsgipythonwsgi

I have become aware that the print statements in my django app are causing wsgi to error and fail. Without going over all my code and removing/commenting out the print statements, is there a way I can disable them when running wsgi. It needs to be a simple as possible.

Thanks

Best Answer

Use WSGIRestrictStdout option:

WSGIRestrictStdout Off

or replace sys.stdout with sys.stderr in Django WSGI star script:

import sys
sys.stdout = sys.stderr

Writing To Standard Output

No WSGI application component which claims to be portable should write to standard output. That is, an application should not use the Python print statement without directing output to some alternate stream. An application should also not write directly to sys.stdout.