CGI and HTTP header problem

Toralf Wittner wittner at uni-duesseldorf.de
Sat Mar 11 18:57:00 EST 2000


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




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



More information about the Python-list mailing list