[英]Eve (Flask) app responds with no content to uWSGI
我有一个非常简单的应用程序,其中包含两个利用Eve框架的资源,该框架又基于Flask 。
内置的 WSGI 工作正常,但 uWSGI 没有从脚本接收内容。 我是否正确配置了 WSGI 以与 Eve 通信,还是需要修改默认的 Flask 配置?
我通过一个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()
内置的 WSGI 在
main()
上没有*args, **kwargs
情况下工作得很好。
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
我已禁用和启用线程,但在任何一个方向都没有成功。
从 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)
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>
这似乎是响应中的编码不匹配,因此 uWSGI 日志中的响应为 0 字节。 但是,我没有涉及任何编码,并且在没有任何更改的情况下尝试了配置文件中的http
和http-socket
指令。 我怀疑,由于 uWSGI 将请求发送给 Eve,因此框架没有正确解析它。 我已经查看了用于 运行包含的 WSGI的代码, 但我似乎无法找到我需要重写以透明地解析请求的内容(如果有的话)。
您需要返回应用程序的一个实例,然后将其传递到 uwsgi ini 文件中。 像这样。
在 main.py 中:
def main(): app = .... // whatever you want return app app = main()
然后在 uwsgi 文件中:
[uwsgi]
http = 127.0.0.1:5000
module = main
callable = app
Flask 中的默认 wsgi 可以工作,因为它看起来在 serve() 函数中,您已经在其中创建了应用程序的实例。
但是 uwsgi 与那个 serve() 函数无关。
它只是在您的主文件中查找可调用实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.