[Tutor] Web Server
Kent Johnson
kent37 at tds.net
Mon Feb 18 20:05:56 CET 2008
Ryan wrote:
> I copied a webserver from one O'Reilly's books, but it only works under
> windows. Can anyone tell me what to change to get it to work under
> linux?
What happens when you try it? My guess is you get an error opening a
socket to listen to port 80. Try port 8000.
Kent
> Here is the code:
>
> webdir = '.'
> port = 80
>
> import os, sys
> from BaseHTTPServer import HTTPServer
> from CGIHTTPServer import CGIHTTPRequestHandler
>
> if len(sys.argv) > 1: webdir = sys.argv[1]
> if len(sys.argv) > 2: port = int(sys.argv[2])
> print 'webdir "%s", port %s' % (webdir, port)
>
> if sys.platform[:3] == 'win':
> CGIHTTPRequestHandler.have_popen2 = False
> CGIHTTPRequestHandler.have_popen3 = False
> sys.path.append('cgi-bin')
>
> os.chdir(webdir)
> srvaddr = ("", port)
> srvobj = HTTPServer(srvaddr, CGIHTTPRequestHandler)
> srvobj.serve_forever()
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list