gunicorn or flask printing to console causes internal server error

℡╲_俬逩灬. 提交于 2021-02-17 05:12:36

问题


I have a flask app which I am hosting using the wsgi gunicorn. A while back I found out that having print statements in my code caused my program to throw a 500 internal server error (when I didn't have an SSH connection with the server). I assume this is because since I wasn't connected to the server there was no where to print.

However, I now am encountering a bug with a similar nature. I have an python script that will send requests to my web server. When I have an SSH connection with the web server the script runs fine. However when I don't I receive a 500 internal server error. I eventually found out that for some reason when I send a request via my python script gunicorn or flask decides to print it to the console. I should mention that when I visit the webpage on a browser nothing is printed and the app works just fine. The output looks something like this.

Host: [domain].com
X-Real-Ip: [my ip address]
X-Forwarded-For: [my ip address]
X-Forwarded-Proto: https
Connection: close
Content-Length: 18910
User-Agent: python-requests/2.25.1
Accept-Encoding: gzip, deflate
Accept: */*
Content-Type: application/x-www-form-urlencoded
Cookie: session=[session cookie]

There are really two fixes for this: 1. stop gunicorn or flask from printing to the console. 2. Figure out how to ignore errors surrounding printing to the console.

So if anyone knows how to accomplish one of the fixes above that would be helpful.

来源:https://stackoverflow.com/questions/66144680/gunicorn-or-flask-printing-to-console-causes-internal-server-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!