简体   繁体   English

Eve (Flask) 应用程序响应 uWSGI 没有内容

[英]Eve (Flask) app responds with no content to uWSGI

I have very simple application with two resources leveraging the Eve framework, which is in turn based on Flask .我有一个非常简单的应用程序,其中包含两个利用Eve框架的资源,该框架又基于Flask

TL;DR:特尔;博士:

The built in WSGI works fine, but uWSGI is not receiving content from the script.内置的 WSGI 工作正常,但 uWSGI 没有从脚本接收内容。 Am I configuring the WSGI correctly to communicate with Eve, or do I need to modify the default Flask configuration?我是否正确配置了 WSGI 以与 Eve 通信,还是需要修改默认的 Flask 配置?

Eve前夕

I manage everything (at the moment) through a single main.py which looks like this:我通过一个main.py管理一切(目前),如下所示:

## main.py
from eve import Eve
from settings import these_settings

def post_post_callback():
    ...
def post_get_callback():
    ...

# def main(): 
#       `-> throws TypeError, main() expects exactly 0 arguments
def main(*args, **kwargs):
    app = Eve(settings=these_settings)
    app.on_post_POST += post_post_callback
    app.on_post_GET += post_get_callback
    return app

def serve():
    app = main()
    app.run()

The built-in WSGI works just fine without *args, **kwargs on main() .内置的 WSGI 在main()上没有*args, **kwargs情况下工作得很好。

uWSGI uWSGI

The configuration for uWSGI has been taken from here with modification only for a virtual environment, log, and module and callable: uWSGI 的配置取自此处,仅针对虚拟环境、日志和模块以及可调用项进行了修改:

[uwsgi]
http = 127.0.0.1:5000
module = main
callable = main
virtualenv = /Users/me/.local/share/virtualenvs/my_app-qtX0KE_c
processes = 4
enable-threads = true
threads = 2
logto = uwsgi.log

I have disabled and enabled threading with no success in either direction.我已禁用和启用线程,但在任何一个方向都没有成功。

Logs and Responses日志和响应

From the uWSGI logs:从 uWSGI 日志:

*** Starting uWSGI 2.0.17.1 (64bit) on [Fri Sep 28 15:29:28 2018] ***
compiled with version: 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2) on 27 September 2018 19:43:49
os: Darwin-17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
nodename: GVOMB0036.local
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /Users/me/my_app
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 1418
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 127.0.0.1:5000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:51246 (port auto-assigned) fd 3
Python version: 2.7.15 (default, Sep 18 2018, 20:16:18)  [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
Set PythonHome to /Users/me/.local/share/virtualenvs/my_app-qtX0KE_c
Python main interpreter initialized at 0x7f9966d01280
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 416560 bytes (406 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x7f9966d01280 pid: 23625 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 23625)
spawned uWSGI worker 1 (pid: 23628, cores: 2)
spawned uWSGI worker 2 (pid: 23629, cores: 2)
spawned uWSGI worker 3 (pid: 23630, cores: 2)
spawned uWSGI worker 4 (pid: 23631, cores: 2)
spawned uWSGI http 1 (pid: 23632)
[pid: 23630|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 460 bytes} [Fri Sep 28 15:29:39 2018] GET / => generated 0 bytes in 9 msecs (HTTP/1.1 500) 0 headers in 0 bytes (2 switches on core 0)

The main() method is being hit by uWSGI, and is passing two objects (which I logged to file): main()方法正在被 uWSGI 命中,并且正在传递两个对象(我记录到文件中):

{'wsgi.multiprocess': True, 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'UWSGI_ROUTER': 'http', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING': '', 'HTTP_USER_AGENT': 'PostmanRuntime/7.3.0', 'HTTP_CONNECTION': 'keep-alive', 'SERVER_NAME': 'GVOMB0036.local', 'REMOTE_ADDR': '127.0.0.1', 'wsgi.url_scheme': 'http', 'SERVER_PORT': '5000', 'uwsgi.node': 'GVOMB0036.local', 'HTTP_POSTMAN_TOKEN': '12bd37b7-7d07-4701-a59b-54a5e3ee108d', 'uwsgi.core': 0, 'wsgi.input': <uwsgi._Input object at 0x100f674b0>, 'HTTP_HOST': '127.0.0.1:5000', 'wsgi.multithread': True, 'HTTP_CACHE_CONTROL': 'no-cache', 'REQUEST_URI': '/schemata', 'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0), 'wsgi.run_once': False, 'wsgi.errors': <open file 'wsgi_errors', mode 'w' at 0x101c41f60>, 'REMOTE_PORT': '32486', 'uwsgi.version': '2.0.17.1', 'wsgi.file_wrapper': <built-in function uwsgi_sendfile>, 'HTTP_ACCEPT_ENCODING': 'gzip, deflate', 'PATH_INFO': '/'}
<built-in function uwsgi_spit>

Notes笔记

This seems like it is a mismatch of encoding in the response, hence the 0 byte response in the uWSGI logs.似乎是响应中的编码不匹配,因此 uWSGI 日志中的响应为 0 字节。 However, I'm not touching any of encoding, and I tried both the http and http-socket directives in the config file without any changes.但是,我没有涉及任何编码,并且在没有任何更改的情况下尝试了配置文件中的httphttp-socket指令。 I have a suspicion that, since uWSGI is sending the request on to Eve, the framework isn't parsing it correctly.我怀疑,由于 uWSGI 将请求发送给 Eve,因此框架没有正确解析它。 I've looked through the code for running the included WSGI , and I can't seem to find what, if anything, I need to override to parse the request transparently.我已经查看了用于 运行包含的 WSGI的代码, 我似乎无法找到我需要重写以透明地解析请求的内容(如果有的话)。

  • uWSGI can not find your main inside main.py uWSGI 在 main.py 中找不到你的 main
  • you need to return an instance of your app and then pass it in uwsgi ini file.您需要返回应用程序的一个实例,然后将其传递到 uwsgi ini 文件中。 like this.像这样。

    in main.py:在 main.py 中:

     def main(): app = .... // whatever you want return app app = main()

then in uwsgi file:然后在 uwsgi 文件中:

[uwsgi]
http = 127.0.0.1:5000
module = main
callable = app

default wsgi in flask works because it looks inside serve() function in which you have made an instance of your app. Flask 中的默认 wsgi 可以工作,因为它看起来在 serve() 函数中,您已经在其中创建了应用程序的实例。

but uwsgi has nothing to do with that serve() function.但是 uwsgi 与那个 serve() 函数无关。

it just looks for callable instance in your main file.它只是在您的主文件中查找可调用实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM