python cgi script not understood as html

P

Philippe C. Martin

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)
 
P

Philippe C. Martin

the title should say "python cgi script html output not understood as html"
 
M

Mitja Trampus

Philippe said:
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.
 
P

Peter Hansen

Philippe said:
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
 
P

Philippe C. Martin

Many thanks !!

Regards,

Philippe



Mitja said:
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.
 
P

Philippe C. Martin

It is, thanks.

Philippe



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

-Peter
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top