GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, April 27, 2011

Python - Web Server

There's some options to build a web server using Python:
1. Using BaseHTTPServer
from BaseHTTPServer import *
def run(server_class=BaseHTTPServer.HTTPServer,
    handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
    server_address = ("", 8000)
    httpd = server_class(server_address, handler_class)
    httpd.server_forever()

run()

2. Using SimplerHTTPServer
import SimpleHTTPServer
import SocketServer

PORT = 8001

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SockerServer.TCPServer(("", PORT), Handler)
print "Serving at port: ', PORT
httpd.serve_forever()

Or you can invoke it using
python.exe -m SimpleHTTPServer 8000
Share/Bookmark

No comments:

Post a Comment