Python Flask server crashing on GET request to specific endpoint:

僤鯓⒐⒋嵵緔 提交于 2019-12-10 10:44:15

问题


All,

I have an API with two endpoints built using Flask. I am using an nginx/uwsgi combo for serving and I am getting an odd error whenever I send a GET request to one of the end points. The other endpoint works just fine.

Here is the output from my uwsgi log from a get request

File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1646, in request_context
    return RequestContext(self, environ)
File "/usr/local/lib/python2.7/dist-packages/flask/ctx.py", line 166, in __init__
    self.url_adapter = app.create_url_adapter(self.request)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in create_url_adapter
    server_name=self.config['SERVER_NAME'])
File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1196, in bind_to_environ
    environ['REQUEST_METHOD'], environ.get('PATH_INFO'),
KeyError: 'REQUEST_METHOD'

And, here is the output from the nginx error log from a get request

2013/12/26 15:22:16 [error] 833#0: *9 upstream prematurely closed connection while reading response header from upstream, 
client: 71.71.53.31, server: scholarly, 
request: "GET /citelet/ HTTP/1.1", 
upstream: "uwsgi://unix:///tmp/citelet.sock:", 
host: "162.243.219.38"

I apologize for the vagueness of this question. I've set up this server several times on the same hardware, with the same libraries, and had no issues before. The error is confusing and I'm not really sure where to start looking.

Thanks in advance!


回答1:


Stupid mistake. There was an error in my nginx config. It was pointing to a non-existent socket.

server {
    listen   80;
          server_name scholarly;
      # crowdscholar endpoint
        location /crowdscholar {
            uwsgi_pass unix:///tmp/crowdscholar.sock;
        include uwsgi_params;
        # strip path before handing it to app
        uwsgi_param SCRIPT_NAME /crowdscholar;
        uwsgi_modifier1 30;
    }
    # citelet endpoint
        location /citelet {
            uwsgi_pass unix:///tmp/citelet.sock;
        include uwsgi_params;
        # strip path before handing it to app
        uwsgi_param SCRIPT_NAME /citelet;
        uwsgi_modifier1 30;
    }
}



回答2:


just for reference: I was getting the same error, and realized I'd forgotten to add include uwsgi_params; as in user1558914's answer.

then it still wasn't working after make restart because I had my uwsgi restart rule, which was failing, ahead of the nginx restart. once I manually restarted nginx with /etc/init.d/nginx restart, the KeyError ceased.



来源:https://stackoverflow.com/questions/20790833/python-flask-server-crashing-on-get-request-to-specific-endpoint

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