I’m trying to return a file of processed data to a webapp user using the web.py framework. In this example the file is named plate3_v4.gb. I’m trying to return it with the name results.gb. This is based off of this thread.
Here’s the code:
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
When I go to the page that I think should serve the data to me I get
mod_wsgi (pid=21773): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/code.py'.
IOError: failed to write data
in my error log.
Any thoughts?
First off, a WSGI application should never set Transfer-Encoding response header itself. Only the underlying web server should do that. For mod_wsgi, Apache should do that automatically so long as no response content length provided.
As to the error, it indicates that the client closed the socket connection prior to it reading all the data which was returned.