Python的Flask服务器崩溃GET请求到特定的端点: [英] Python Flask server crashing on GET request to specific endpoint:

查看:619
本文介绍了Python的Flask服务器崩溃GET请求到特定的端点:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,

我有一个使用Flask构建的两个端点的API。我正在使用nginx / uwsgi组合服务,每当我发送一个GET请求到一个端点时,我得到一个奇怪的错误。另一个端点工作得很好。



这里是我的uwsgi日志从一个get请求的输出

 文件/usr/local/lib/python2.7/dist-packages/flask/app.py,第1646行,在request_context中
返回RequestContext(self,environ)
文件/usr/local/lib/python2.7/dist-packages/flask/ctx.py,第166行,在__init__
self.url_adapter = app.create_url_adapter(self.request)
文件/usr/local/lib/python2.7/dist-packages/flask/app.py,行1475,在create_url_adapter
server_name = self.config ['SERVER_NAME'])
文件/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py,第1196行,在bind_to_environ
environ ['REQUEST_METHOD'],environ.get('PATH_INFO'),
KeyError:'REQUEST_METHOD'

这里是nginx错误日志的输出get请求

  2013/12/26 15:22:16 [error] 833#0:* 9上游提前关闭连接来自上游的响应头,
client:71.71.53.31,server:scholarly,
request:GET / citelet / HTTP / 1.1,
upstream:uwsgi:// unix:/ //tmp/citelet.sock:,
host:162.243.219.38

我对这个问题的模糊性表示抱歉。我已经在相同的硬件上用相同的库建立了这个服务器几次,之前没有问题。

在此先感谢!

解决方案

愚蠢的错误。在我的nginx配置中有一个错误。它指向一个不存在的套接字。

  server {
listen 80;
server_name学术;
#crowdscholar端点
位置/ crowdscholar {
uwsgi_pass unix:///tmp/crowdscholar.sock;
包含uwsgi_params;
#strip路径,然后交给应用
uwsgi_param SCRIPT_NAME / crowdscholar;
uwsgi_modifier1 30;
}
#citelet端点
位置/ citelet {
uwsgi_pass unix:///tmp/citelet.sock;
包含uwsgi_params;
#strip路径,然后将其交给应用
uwsgi_param SCRIPT_NAME / citelet;
uwsgi_modifier1 30;
}
}


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!

解决方案

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;
    }
}

这篇关于Python的Flask服务器崩溃GET请求到特定的端点:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆