Python和uWSGI:来自迭代器的未处理对象



请帮助我了解如何使用uWSGI。这里是我的Python文件:

# cat /var/www/test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ["<h1 style='color:blue'>Test</h1>"]

我用以下命令启动uWSGI:

# uwsgi --socket 0.0.0.0:8080 --protocol=http --plugin python39 --pythonpath /var/www/ -w test

在控制台得到这个:

*** Starting uWSGI 2.0.19.1 (64bit) on [Sat Sep  4 20:02:16 2021] ***
compiled with version: 10.3.0 on 02 September 2021 21:45:57
os: Linux-5.10.52-gentoo-x86_64 #5 SMP Fri Aug 20 00:32:31 EEST 2021
nodename: virtuala-servilo-2
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /tmp
detected binary path: /usr/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7854
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
*** RRDtool library available at 0x55ab7e467000 ***
uwsgi socket 0 bound to TCP address 0.0.0.0:8080 fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.9.6 (default, Aug  8 2021, 17:26:32)  [GCC 10.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55ab7e46fed0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55ab7e46fed0 pid: 14817 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 14817, cores: 1)

看起来不错,但是当我尝试连接到我的服务器时,我收到这是控制台:

[ERROR] Unhandled object from iterator: "<h1 style='color:blue'>Test</h1>" (0x7f4fe2a28c30)
[pid: 14817|app: 0|req: 1/1] 85.143.221.42 () {24 vars in 284 bytes} [Sat Sep  4 20:02:21 2021] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)

但是如果我将脚本中的最后一个字符串替换为yield None-我不会收到此错误。

根据文档,python3要求返回类型为字节。

最新更新