gpt4 book ai didi

python - uwsgi 返回空白输出

转载 作者:太空狗 更新时间:2023-10-29 22:22:21 25 4
gpt4 key购买 nike

我在 CentOS 6 服务器上安装了 nginx 和 uwsgi。当我将一些数据发布到网络服务器时,它被正确处理但没有返回输出。如果我在应用程序函数返回之前打印生成的 html,则 HTML 在控制台中正确显示,但控制台上的下一行是:

[pid: 31650|app: 0|req: 2/2] <server ip> () {48 vars in 873 bytes} [Mon Sep 15 18:19:45 2014] POST / => generated 0 bytes in 10583 msecs (HTTP/1.1 200) 1 headers in 44 bytes (418 switches on core 0)

我增加了套接字超时,但没有任何影响。

编辑:我为此设置了一个奇怪的解决方法。我的 html 被存储在变量“html”中。我更改了我的代码:

return [html] #This would not return any output even though 'print html' was fine

收件人:

open('/tmp/ot.txt', 'w').write(html)
d = open('/tmp/ot.txt').read()
return [d] #This works!

我不想使用我的解决方法。任何想法为什么这行得通而原来的行不通。 Python版本为2.6.6

最佳答案

你的问题很可能是 uwsgi 默默地丢弃了任何 unicode 对象,并且只显示字节字符串。这就是为什么当你写入一个文件并读回它时,它起作用了,因为 write() 悄悄地将 unicode 转换为 ascii 编码(如果有任何 ord(x) > 127 则引发异常),并且read() 返回字节。

这种情况下的解决方案是返回 [html.encode('utf8')] 或您正在使用的任何编码。

我之所以发现这一点,是因为我在任何 .md 文件上调用了 markdown.markdown(text),并附加了 .html 文件直接到我的输出。只有 HTML 显示,而不是 Markdown ,哪个模块返回 Unicode。

关于python - uwsgi 返回空白输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25854510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com