CGIHTTPServer windoze hair-loss program

Sandy Norton sandskyfly at hotmail.com
Thu Mar 7 13:13:00 EST 2002


Hi folks,

I've been trying without some success to get CGIHTTPServer working with 
windows XP (or win2k) and Python 2.2 

Simply put, I can't get the POST method to work as desired in CGIHTTPServer.
Or maybe my code is buggy...

The following is true of my particular situation:
    
-  The script is run correctly when executed (1)directly from the browser
    address bar or (2) from the commandline.
   
   (1) So after running cgiserve, if I manually type
   "http://localhost:8000/cgi-bin/testcgi.py?a=1" into the browser 
   I get the correct output which is:
   
   -output----------------------------------------------------------------
   Input: a --> 1

   Finished!
   -----------------------------------------------------------------------
   
   (2) Equally if I run the testcgi.py script from the commandline
   e.g. "python testcgi.py a=1" I also get correct output.

-  However, when I click on the submit button on the html form while running
   CGIHTTPServer the interpreter doesn't execute the script, nor does 
   it pass values, and all I get is a "The page cannot be displayed" 
   error. Subsequently hitting refresh on the browser then runs the script 
   correctly, albeit without any values passed.


Here is the test code:

cgiserve.py
--------------------------------------------------------------------------
from CGIHTTPServer import test as serve
if __name__=='__main__': serve()
--------------------------------------------------------------------------

test.html
--------------------------------------------------------------------------
<html>
 <head>
  <title>CGI Test</title>
 </head>
 <body>
 <form method="POST" action="cgi-bin\testcgi.py">
    <input type='text' name='mytext' size=60>
    <input type='submit' value=' ok '>
 </form>
 </body>
</html>
--------------------------------------------------------------------------

cgi-bin\testcgi.py
--------------------------------------------------------------------------
#!python

import cgi   
print "Content-Type: text/plain\n\n"
form = cgi.FieldStorage()
for name in form.keys():
    print "Input: " + name + " --> " + form[name].value + "\n"
print "Finished!"
--------------------------------------------------------------------------

Log output while running cgiserve.py
--------------------------------------------------------------------------
C:\src\tst\>cgiserve
Serving HTTP on 0.0.0.0 port 8000 ...
localhost - - [07/Mar/2002 20:17:38] "GET /test.html HTTP/1.1" 200 -
localhost - - [07/Mar/2002 20:17:47] "POST /cgi-bin/testcgi.py HTTP/1.1" 200 -
localhost - - [07/Mar/2002 20:17:47] command: C:\Engines\Python22\python.exe 
-u C:\src\tst\cgi-bin\testcgi.py ""
localhost - - [07/Mar/2002 20:17:47] CGI script exited OK
--------------------------------------------------------------------------

Now is there something in particular that I'm doing wrong here. I'm kinda 
pulling my hair out by now. )-; 

Any help would be greatly appreciated.

Many Thanks,

Sandy



More information about the Python-list mailing list