Differences between revisions 1 and 2
Revision 1 as of 2004-05-31 00:56:49
Size: 1107
Editor: dsl254-010-130
Comment: How to make a very simple web server.
Revision 2 as of 2004-05-31 01:13:16
Size: 1790
Editor: dsl254-010-130
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Scratch code, demonstrating a simple HTTP server: = BaseHTTPServer =

You can use this to make a simple HTTP web server.

== Official Documentation ==

 * [http://www.python.org/doc/2.3.4/lib/module-BaseHTTPServer.html BaseHTTPServer module documentation] - what we use directly
 * [http://www.python.org/doc/2.3.4/lib/module-SocketServer.html SocketServer module documentation] - behind the BaseHttpServer

== Example Code ==
Line 38: Line 47:
See also: DocXmlRpcServer == See Also ==

DocXmlRpcServer

= Discussion =

I'd ultimately like to see a BaseHttpServer here that can both handle XML-RPC requests (with ''that'' request handler,) and normal web requests (with a custom handler.)

Yes- I know and love TwistedPython. But I want to make something that works in a single install. -- LionKimbro [[DateTime(2004-05-31T01:13:16Z)]]

BaseHTTPServer

You can use this to make a simple HTTP web server.

Official Documentation

Example Code

   1 import time
   2 import BaseHTTPServer
   3 
   4 
   5 HOST_NAME = 'something.somewhere.net'
   6 PORT_NUMBER = 80
   7 
   8 
   9 class MyHandler( BaseHTTPServer.BaseHTTPRequestHandler ):
  10     def do_HEAD(s):
  11         s.send_response(200)
  12         s.send_header("Content-type", "text/html")
  13         s.end_headers()
  14     def do_GET(s):
  15         """Respond to a GET request."""
  16         s.send_response(200)
  17         s.send_header("Content-type", "text/html")
  18         s.end_headers()
  19         s.wfile.write( "<html><head><title>Title goes here.</title></head><body><p>This is a test.</p></body></html>" )
  20 
  21 if __name__ == '__main__':
  22     server_class = BaseHTTPServer.HTTPServer
  23     httpd = server_class( (HOST_NAME, PORT_NUMBER),
  24                           MyHandler )
  25     print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
  26     try:
  27         httpd.serve_forever()
  28     except KeyboardInterrupt:
  29         pass
  30     httpd.close()
  31     print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)

See Also

DocXmlRpcServer

Discussion

I'd ultimately like to see a BaseHttpServer here that can both handle XML-RPC requests (with that request handler,) and normal web requests (with a custom handler.)

Yes- I know and love TwistedPython. But I want to make something that works in a single install. -- LionKimbro DateTime(2004-05-31T01:13:16Z)

BaseHttpServer (last edited 2012-04-15 19:54:19 by PaulBoddie)

Unable to edit the page? See the FrontPage for instructions.