[Tutor] THE CGI SERVER SCRIPT

Kirk Bailey idiot1 at netzero.net
Sun Sep 14 14:09:21 EDT 2003


STEVE wrote the server, I simply called a bug in it to his attention; he fixed 
it. I used it, and made sure it was ok to give out copies, then offered it to 
you all.

As for issues; OK, let's see how mine is set up. I have the desktop icon open to 
properties, here's what there is:

1. Target: C:\Python22\pythonw.exe C:\PYTHON22\cgiserver.py
2. Start in: C:\Python22
3. Shortcut key: None
4. Run: Minimized

It runs on port 8080. To access it, the browser must be addressed to:
http://localhost:8080/
It will default to index.html. Paths are below that, and the root directory is 
the one the script finds itself in. Therefore, webpages are to be placed in that 
directory. The images dir is off of that one, which is 'C:\Python22'. Create a 
cgi-bin under it and place the wiki scripts in there. In that, create the 'text' 
dir and place the pages there. Inage files must be in the C:\Python22\images 
directory.

There are known issues with some firewalls. Either start it first, THEN the 
firewall, OR edit the firewall to allow it to work with port 8080, OR shut the 
silly thing off. After all, this is a wiki to be used when off line, after all. 
IF you are good with firewalls, maybe you can get the local browser to access 
the server internally and not have to pass through the firewall at all.



Ole Jensen wrote:

> Concerning the before mentioned cgi script by Steve Holden and Kirk Bailey,
> well I've now tried to experiment with it but I didn't get very far!
> 
> As a matter of fact I was not even able to run the server, I get a traceback
> saying it can't find a a/some module(s).
> 
(Keep reading, there's more after this breif message from python...)
> This is the the traceback:
> Traceback (most recent call last):
>   File "C:\Programmer\python\cgi.py", line 2, in ?
>     import CGIHTTPServer, BaseHTTPServer
>   File "C:\PROGRA~1\python\lib\CGIHTTPServer.py", line 28, in ?
>     import SimpleHTTPServer
>   File "C:\PROGRA~1\python\lib\SimpleHTTPServer.py", line 17, in ?
>     import cgi
>   File "C:\Programmer\python\cgi.py", line 3, in ?
>     httpd=BaseHTTPServer.HTTPServer(('',8080),
> CGIHTTPServer.CGIHTTPRequestHandler)
> AttributeError: 'module' object has no attribute 'CGIHTTPRequestHandler'
> Traceback (most recent call last):
>   File "C:\Programmer\python\cgi.py", line 3, in ?
>     httpd=BaseHTTPServer.HTTPServer(('',80),
> CGIHTTPServer.CGIHTTPRequestHandler)
> AttributeError: 'module' object has no attribute 'CGIHTTPRequestHandler'
> 
> Quite alot actually (compared to what I'm used for), I can't say that I
> fully undstand it, but the way I understand it the error is in the imported
> modules (is that possible!!!)
> 
> I use Python 2.2.3 on WinXP, if that matters.
I have 2.2.1 and it works fine. Intresting.
> The only changes I made to the cgi script was adjusting the libray info in
> the first line, and the port number to 8080 (which I did try to set to 80,
> afterwards).
Try deleting the modified script and replace it wih the unmodified one in the 
zip file and see if it works, maybe there was a unnoticed typo introduced when 
you edited it?

Here is a mouse copy of the one running in my pc RIGHT THIS MINUTE:

#!C:\Python22\pythonw.exe
# COPYRIGHT 2003 Steve Holden, free for personal use.
# Please visit http://www.holdenweb.com/ to learn more!
#
import CGIHTTPServer, BaseHTTPServer
httpd=BaseHTTPServer.HTTPServer(('',8080), CGIHTTPServer.CGIHTTPRequestHandler)
httpd.serve_forever()
#

> 
> The file has been placed in the (root) python library (next to python.exe
> etc).
> 
it goes into c:Python22 - in the 2.2.1 release. If the dir name is different in 
2.2.3, please adjust accordingly. The thing goes in the same dir as 
'pythonw.exe'. If that is a different path, you might want to adjust the 
sheband, although as the command line in the shortcut is directly to 
pythonw.exe, and feeds it cgiserver.py as a command line arguement, this may not 
matter at all.

> I've never been working with cgi-script, let alone setting up cgi servers on
> my PC, so I don't really know it is something I've done wrong as it sounded
> like Kirk got it up and running.
>
OH! Well, then, here is a helloworld script.
#!C:\Python22\pythonw.exe
#
print 'Content-Type: text/html'
print
print "<head><title>This is the OFFICAL HelloWorld program, accept no 
substitutes...</title>" # BEWARE WORD WRAP IN EMAIL TRANSMISSIONS!
print '<body bgcolor="E0E0FF">'
print '<blockquote><center><h1>Helloworld!</h1>'
print '</center><p>'
print "that's it. Goodbye."
print '<P></body></html>'



> I am looking forward to any replies/solutions.
> Olé
> 
> Below is the cgi code:
> #!C:\Programmer\python\pythonw.exe
> import CGIHTTPServer, BaseHTTPServer
> httpd=BaseHTTPServer.HTTPServer(('',80),
> CGIHTTPServer.CGIHTTPRequestHandler)
> httpd.serve_forever()
> 
> 
> 
> 

-- 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Prometheus
  +                              kniht                                +

Fnord.




More information about the Tutor mailing list