Serve.py: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="python"> #!/usr/bin/env python import BaseHTTPServer, CGIHTTPServer import cgitb; cgitb.enable() ## This line enables CGI error reporting import sys import ar...")
 
No edit summary
Line 2: Line 2:
#!/usr/bin/env python
#!/usr/bin/env python
   
   
import BaseHTTPServer, CGIHTTPServer
import BaseHTTPServer, CGIHTTPServer, sys, argparse
import cgitb; cgitb.enable()  ## This line enables CGI error reporting
import cgitb; cgitb.enable()  ## This line enables CGI error reporting
import sys
import argparse


parser = argparse.ArgumentParser(description='Happy to serve you')
parser = argparse.ArgumentParser(description='Happy to serve you')

Revision as of 17:33, 11 November 2013

<source lang="python">

  1. !/usr/bin/env python

import BaseHTTPServer, CGIHTTPServer, sys, argparse import cgitb; cgitb.enable() ## This line enables CGI error reporting

parser = argparse.ArgumentParser(description='Happy to serve you') parser.add_argument('--port', type=int, default=8000, help='the port number to listen to') args = parser.parse_args() server = BaseHTTPServer.HTTPServer handler = CGIHTTPServer.CGIHTTPRequestHandler server_address = ("", args.port) handler.cgi_directories = ["/cgi-bin"] print "Listening on http://localhost:{}".format(args.port) httpd = server(server_address, handler) httpd.serve_forever() </serve>