serving html from a python script in IE

bluegray francoisdutoit at gmail.com
Thu Nov 1 17:56:17 CET 2007


Yes, I have all the necessary shebang and imports. As I said, the
script works fine in Firefox. It's something specific to IE that is
the problem. The following is a test script that also causes IE to
download instead of displaying the page. It works fine elsewhere. I
also did some searching, and python scripts on other servers seem to
work in IE. So it's maybe something specific to my server. I have no
idea what though.

#!/usr/bin/python

print "Content-Type: application/xhtml+xml;charset=utf-8\nCache-
Control: no-cache\n"

print '''<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>An XHTML 1.0 Strict standard template</title>
	<meta http-equiv="content-type"
		content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
</head>

<body>

     <p> Your HTML content here </p>

</body>
</html>'''

kyoso... at gmail.com wrote:
> On Nov 1, 9:52 am, bluegray <bluegraydra... at gmail.com> wrote:
> > I'm writing a script that outputs html. It works fine in Firefox,
> > however, IE wants to download the file instead of displaying the
> > output. I keep getting the file download dialog instead of the html
> > page.
> >
> > I am doing something like this:
> >
> > print 'Content-Type: text/html ; charset=utf-8\nCache-Control: no-cache
> > \n'
> > print '<html><body>some text and html</body></html>'
> >
> > I also tried various things in .htaccess which has the following line:
> >
> > AddHandler cgi-script .py
> >
> > Any help will be appreciated.
>
> Do you have the "shebang" listed at the top of your code (i.e. #!/path/
> to/python)? Are you importing the cgi module at the top of your code?
>
> >From what I've read, you don't need to modify the htaccess file...
>
> See also:
>
> Tutorials:
> http://www.cs.virginia.edu/~lab2q/
> http://wiki.python.org/moin/CgiScripts
> http://www.upriss.org.uk/python/PythonCourse.html
>
> Docs:
> http://www.python.org/doc/essays/ppt/sd99east/index.htm
> http://docs.python.org/lib/module-cgi.html
>
> Mike

Yes, I have all the necessary shebang and imports. As I said, the
script works fine in Firefox. It's something specific to IE that is
the problem. The following is a test script that also causes IE to
download instead of displaying the page. It works fine elsewhere. I
also did some searching, and python scripts on other servers seem to
work in IE. So it's maybe something specific to my server. I have no
idea what though.

#!/usr/bin/python

print "Content-Type: application/xhtml+xml;charset=utf-8\nCache-
Control: no-cache\n"

print '''<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>An XHTML 1.0 Strict standard template</title>
	<meta http-equiv="content-type"
		content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
</head>

<body>

     <p> Your HTML content here </p>

</body>
</html>'''




More information about the Python-list mailing list