[mod_python] req.sendfile() problem

Joseph Barillari joeb at mit.edu
Fri Aug 4 12:29:13 EDT 2006


On Fri, Aug 04, 2006 at 12:15:06PM -0400, Thomas J. Schirripa wrote:
> Before stating my problem, let me say that I am running apache version 2.0.52, mod_python 3.2.8, python 2.3, all on Redhat Enterprise Linux WS release 4.
> 
> Basically I have a webpage where the client uploads a file and some scripts/programs run on the server and produce output files. Some of this output is spit out onto another webpage, but I want to give the client the option to download the output files. Since I am using multiple webpages, I had to figure out a way to transfer data from one page to another. The only sensible solution that I could figure out was to use psp to feed variables from my handlers into hidden form inputs in my template. From the output html page, the client can click a submit button next to the output filename that says "download". The hidden form inputs have the information as to where the file is located on the server, and the action on the form refers to my sendFile handler. That handler looks like this:
> 
> def handler(req):
> 	fields = util.FieldStorage(req)
>         #Note: the filename is an absolute path, so I am going to split that up into directory and filename for clarity
> 	filename = os.path.basename(fields["filename"])
> 	path = os.path.dirname(fields["filename"])
> 	req.headers_out["Content-Disposition"] = "attachment; filename=%s" % filename
> 	req.content_type = "text/plain"
> 	req.sendfile("%s/%s" % (directory, filename))
> 	return apache.OK
> 
> I am not sure if I am using req.header_out or req.content-type correctly or how critical those lines are (I found it in another post), but my problem is that I am getting a file to download with the proper filename, BUT the file has a mod_python error message in it that reads:
> 
> IOError: Could not stat file for reading
> 
> and the error points to the line with req.sendfile(). Can anyone tell me what's going on and how to correct this?
> Thanks,
> Tom


Have you tried adding a 
req.log_error("%s/%s" % (directory, filename))  
above the sendfile line to see if the server is looking in the right place?

Joe

-- 
Joseph Barillari
joeb at mit.edu
107 Ave. Louis Pasteur, Vandy Box 346, Boston, MA 02115
617-519-9250 (mobile)


More information about the Mod_python mailing list