By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

python cgi script not understood as html

P: n/a
Hi,

The following code outputs the actual HTML text to the browser, not the
interpreted text.

Any idea ?

Regards,

Philippe
import cgi
import logging
import auth #this is the one you must implement (or use SCF ;-)

html_ok = """
Content-Type: text/html\n
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">\n
<html>\n
<head>\n
<title>Access Granted</title>\n
<meta name="GENERATOR" content="Quanta Plus">\n
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">\n
</head>\n
<body>\n
<H1>Access Granted</H1>\n
<HR>\n
<H4>Welcome %s </H4>\n
<HR>\n
</body>\n
</html>\n
"""

html_nok = """
"Content-Type: text/html\n\n"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>Access Granted</title>
<meta name="GENERATOR" content="Quanta Plus">
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
</head>
<body>
<H1>Access Denied</H1>
<HR>
</body>
</html>
"""
# DISPLAY ACCESS DENIED PAGE
def Failure():
print html_nok

#DISPLAY ACCESS GRANTED PAGE
def Success(p_data):
print html_ok % (p_data)
Oct 24 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
the title should say "python cgi script html output not understood as html"
Philippe C. Martin wrote:
Hi,

The following code outputs the actual HTML text to the browser, not the
interpreted text.

Any idea ?

Regards,

Philippe
import cgi
import logging
import auth #this is the one you must implement (or use SCF ;-)

html_ok = """
Content-Type: text/html\n
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">\n
<html>\n
<head>\n
<title>Access Granted</title>\n
<meta name="GENERATOR" content="Quanta Plus">\n
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">\n
</head>\n
<body>\n
<H1>Access Granted</H1>\n
<HR>\n
<H4>Welcome %s </H4>\n
<HR>\n
</body>\n
</html>\n
"""

html_nok = """
"Content-Type: text/html\n\n"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>Access Granted</title>
<meta name="GENERATOR" content="Quanta Plus">
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
</head>
<body>
<H1>Access Denied</H1>
<HR>
</body>
</html>
"""
# DISPLAY ACCESS DENIED PAGE
def Failure():
print html_nok

#DISPLAY ACCESS GRANTED PAGE
def Success(p_data):
print html_ok % (p_data)


Oct 24 '05 #2

P: n/a
Philippe C. Martin wrote:
Hi,

The following code outputs the actual HTML text to the browser, not the
interpreted text.

Any idea ?

html_ok = """
Content-Type: text/html\n
<html>
...
"""


Avoid the starting newline (before content-type).
Add at least TWO newlines after content-type.

Or use a package to handle the HTTP stuff for you.
Oct 24 '05 #3

P: n/a
Philippe C. Martin wrote:
The following code outputs the actual HTML text to the browser, not the
interpreted text.

html_ok = """
Content-Type: text/html\n
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">\n


HTTP header lines must end with \r\n, not just with \n. Not sure this
is the solution to your specific problem though...

-Peter
Oct 24 '05 #4

P: n/a
Many thanks !!

Regards,

Philippe

Mitja Trampus wrote:
Philippe C. Martin wrote:
Hi,

The following code outputs the actual HTML text to the browser, not the
interpreted text.

Any idea ?

html_ok = """
Content-Type: text/html\n
> <html>
> ...
> """


Avoid the starting newline (before content-type).
Add at least TWO newlines after content-type.

Or use a package to handle the HTTP stuff for you.


Oct 24 '05 #5

P: n/a
It is, thanks.

Philippe

Peter Hansen wrote:
Philippe C. Martin wrote:
The following code outputs the actual HTML text to the browser, not the
interpreted text.

html_ok = """
Content-Type: text/html\n
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">\n


HTTP header lines must end with \r\n, not just with \n. Not sure this
is the solution to your specific problem though...

-Peter


Oct 24 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.