gpt4 book ai didi

python - 尝试提供文件时出现 IO 错误

转载 作者:行者123 更新时间:2023-11-30 23:41:44 24 4
gpt4 key购买 nike

我正在尝试使用 web.py 框架将处理后的数据文件返回给 webapp 用户。在此示例中,文件名为 Plate3_v4.gb。我正在尝试使用名称 results.gb 返回它。这是基于 this thread .

代码如下:

class ServeHandler():
def GET(self):
web.header("Content-Disposition", "attachment; filename=%s" %"results.gb")
web.header("Content-Type", "gb")
web.header('Transfer-Encoding','chunked')
f = open('/usr/local/www/wsgi-scripts/uploads/plate3_v4.gb','rb')
while 1:
buf = f.read(1024 * 8)
if not buf:
break
yield buf

当我转到我认为应该向我提供数据的页面时,我得到

mod_wsgi (pid=21773): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/code.py'.
IOError: failed to write data

在我的错误日志中。

有什么想法吗?

最佳答案

首先,WSGI 应用程序永远不应该设置 Transfer-Encoding 响应 header 本身。只有底层 Web 服务器应该这样做。对于 mod_wsgi,只要没有提供响应内容长度,Apache 就会自动执行此操作。

该错误表明客户端在读取所有返回的数据之前关闭了套接字连接。

关于python - 尝试提供文件时出现 IO 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11866333/

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