1
我正在嘗試使用web.py框架將已處理數據的文件返回給webapp用戶。在這個例子中,該文件被命名爲plate3_v4.gb。我試圖用名稱results.gb返回它。這是基於this thread。嘗試提供文件時發生IOerror錯誤
下面的代碼:
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
在我的錯誤日誌。
有什麼想法?
感謝有關Transfer Encoding的信息,但真的有必要不要設置它?如果web.py應用程序作爲獨立應用程序和mod_wsgi應用程序使用會怎樣? (我只是想知道,因爲這個問題是基於我在webpy組發佈的代碼) – 2012-08-09 06:19:44
這不是您的WSGI應用程序,它以所需格式格式化響應內容。如果你這樣做,你違反了WSGI規範,那麼底層服務器領域就會擔心這一點。 http://www.python.org/dev/peps/pep-0333/#other-http-features – 2012-08-09 08:33:57
謝謝,那麼這個食譜條目http://webpy.org/cookbook/streaming_large_files也是不正確的,因爲它告訴設置分塊標題。 – 2012-08-09 09:54:57