CGI and HTTP header problem

Shichang Zhao shichang at icubed.com
Sat Mar 11 19:17:10 EST 2000


-----Original Message-----
From:	Toralf Wittner [SMTP:wittner at uni-duesseldorf.de]
Sent:	Saturday, March 11, 2000 11:57 PM
To:	python-list at python.org
Subject:	Re: CGI and HTTP header problem

Finally I managed it somehow ;>

Instead of writing two 'print' statements with HTTP headers, one should
better type:


> print "Content-type: application/x-tar\nContent-disposition: attachment; 
filename=%s\n" % fname

This method works with Netscape, and have problems with IE when fname has 
space, in which case one need to quote the filename value: filename="%s" % 
fname.

That is one of the problem I have. If I do not quote the filename value, 
then things come to be ok.





Toralf Wittner wrote:
>
> Hi all,
>
> the following CGI script should handle the download of an item
> previously selected via HTTP formular:
>
> > #! /usr/bin/env python
> >
> > import cgi
> > from urllib import urlopen
> >
> > form = cgi.FieldStorage()
> > fname = form['download_item'].value
> > print "Content-type: application/x-tar\n"
> > file_object = 'http://www.server.url' + fname
> > print urlopen(file_object).read()
>
> While it basically works, there is an annoying problem with the filename
> the 'Save as' browser dialog suggests. It offers the name of the CGI
> script rather than the name of the file one has chosen. As far as I can
> see, this is a problem with the HTTP header.
> I tried to add:
>
> > print "Content-disposition: attachment; filename=%s\n" % fname
>
> after the first 'print' statement which changes nothing. I think that
> something similar should solve this problem, but I don't know how...
> Maybe someone could give me a hint?
>
> Thanks in advance,
> Toralf
--
http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list