python - 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 需要返回字节类型。
推荐阅读
- amazon-web-services - 获取存储桶大小所需的 S3 权限?
- angular - 如何在 angular 7 中的订阅中将变量获取到控制台?
- python - Python 调用的 PFTK 命令无法正常工作
- django - django 中有 Reverse-ForeignKey 吗?
- apache-spark - Yarn 应用程序卡在 ACCEPTED 状态
- google-apps-script - 基于特定单元格的编辑触发器
- arrays - 如何将 2 个不同的数组放在列表视图的不同列中
- javascript - MySQL值更改时如何播放声音
- c++ - Bind() Windows Socket 适用于 IPv4 但不适用于 IPv6
- linux - 无法将文件 rsync 到 AWS:没有这样的文件或目录