serving html from a python script in IE

B

bluegray

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.
 
K

kyosohma

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
 
B

bluegray

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>'''

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?


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>'''
 
R

Richard Brodie

print "Content-Type: application/xhtml+xml

That's your problem. You can't use that Mime type
because IE doesn't support XHMTL. No "appendix C"
hair splitting comments, please.
 
J

J. Cliff Dyer

bluegray said:
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.
If you take out the space between text/html and ; it works just fine.

(In other words, there is no mime-type "text/html ")

Cheers,
Cliff
 
B

bluegray

If you take out the space between text/html and ; it works just fine.
(In other words, there is no mime-type "text/html ")

Thanks! That did it. What a difference a space makes ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top