Hallo zusammen, ich versuche die Eingaben eines HTML-Formulars per POST an ein CGI-Skript zu senden. Ich schaffe es aber irgendwie nicht den Inhalt des POST im CGI-Skript per Python auszulesen.
Hier mein Quelltext (kopiert von http://www.elvenware.com/charlie/development/web/Python/PythonScripts.html).
Das Python CGI-Skript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #!/usr/bin/python import cgi; import cgitb cgitb.enable() def print_header(): print """Content-type: text/html\n <!DOCTYPE html> <html> <body>""" def print_close(): print """</body> </html>""" def display_data(param1, param2): print_header() print "<p>Param1 = " + param1 + "</p>" print "<p>Param2 = " + param2 + "</p>" print_close() def display_error(): print_header() print "<p>An Error occurred parsing the parameters passed to this script.</p>" print "<p>Try something like:</p>" print "<p><strong>http://localhost/SimpleCgi.py?param1=1¶m2=2</strong></p>" print_close() def main(): form = cgi.FieldStorage() if (form.has_key("param1") and form.has_key("param2")): display_data(form["param1"].value, form["param2"].value) else: display_error() main() |
Und hier das HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html> <html> <head> <title>Call SimpleCgi.py</title> <link href="index.css" rel="stylesheet" type="text/css" /> </head> <body> <form action="/cgi-bin/test.py" method="POST"> <div> <span class="rowName">Number One: </span><input name="param1" type="text"> </div> <div> <span class="rowName">Number Two: </span><input name="param2" type="text"> </div> <div><input type="submit" value="Submit Query"></div> </form> </body> </html> |
Ich bekomme nach Ausführung immer wieder das was die Methode display_error ausführt angezeigt. Vermutlich gibt cgi.FieldStorage() nichts zurück. Aber warum?
Ich bin blutiger Anfänger. Sicherlich handelt es sich um einen trivialen Fehler ☹ Ich finde den aber nicht ...
Vielleicht kann mir ja einer von euch hier weiterhelfen ...
Achso, das Skript und das html liegen auf einem dogado-Webspace. Laut vorherigen Fehlermeldungen handelt es sich um einen Apache 2
Danke ...
Grüße - Stefan