CGI-Script
Andy Froemmel
andy.froemmel at sap.com
Mon Feb 24 08:59:58 EST 2003
Hallo,
I have running a HTTPCGI.py :
import BaseHTTPServer
import CGIHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["/cgi-bin"]
PORT = 8000
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "Service an Port", PORT
httpd.serve_forever()
furthermore I send data form a HTML-Side:
<html>
<head>
<title>Beispiel-Formular für Python</title>
</head>
<body bgcolor="#ffffdf" text="#000000" link="#0000ff"
vlink="#800080" alink="#ff0000">
<h2> Ein Beispiel-Formular (CGI in Python)</h2>
<form action="/cgi-bin/trex.py" method="post"
name="beispiel">
<p>
Die erste GUID<br>
<input type="text" size="70" name="GUID1">
</p>
<p>
Die zweite GUID<br>
<input type="text" size="70" name="GUID2">
</p>
<br>
<p>
Der erste Host<br>
<input type="text" size="20" name="HOST1">
</p>
<br>
<p>
Der zweite Host<br>
<input type="text" size="20" name="HOST2">
</p>
<br>
<input type="SUBMIT" value="Abschicken">
<input type="RESET" value="Lieber doch nicht . . .">
</form>
</body>
</html>
to the following py-script:
import cgi
import sys
import traceback
fname = 'log_cgi.txt'
fname1 = 'error_cgi.txt'
def ausgabe(g1, g2, h1, h2):
nachricht =''
nachricht = g1 + g2 + h1 + h2 + '\n<br>\n'
return nachricht
# main
sys.stderr = sys.stdout
print "Content-Type: text/html\n\n"
form=cgi.FieldStorage()
if form.has_key("GUID1") and form.has_key("GUID2") and
form.has_key("HOST1") and form.has_key("HOST2"):
if form["GUID1"].value != "" and
form["HOST1"].value != "":
form_ok = 1
g1 = form["GUID1"].value
g2 = form["GUID2"].value
h1 = form["HOST1"].value
h2 = form["HOST2"].value
content = str(g1 + g2 + h1 + h2)
file = open(fname, 'w')
file.write(content)
file.close()
#print "Content-Type: text/html\n\n"
print '</title>\n</head>\n<body
bgcolor="#ffffdf" text="navy">\n'
#print ausgabe(g1, g2, h1, h2)
print str(g1)
else:
print "<html><head><title>\n"
print "Python is calling you!\n"
print '</title>\n</head>\n<body bgcolor="#ffffdf"
text="navy">\n'
print 'da ist noch ein Fehler'
#print ausgabe(g1, g2, h1, h2)
print "</body>\n</html>\n\n"
The process is running (the data form the HTML-SideDer Vorgang läuft soweit
auch durch (d.h., die
Formulardaten werden auch in die Datei geschrieben),
nur bekomme ich keine Responseseite angezeigt.
D.h., nachdem ich das Formular wegschicken, kommt
"The page cannot be displayed". Wenn ich danach einen
refresh der Seite machen, wird richtigerweise die
"else-Funktion" aufgerufen und als HTML ausgegeben.
Frage:
Warum kann das Script die Formulardaten nicht als HTML
wiedergeben??
Danke und Grüße,
Andy
[...]
More information about the Python-list
mailing list