Skip to content

Instantly share code, notes, and snippets.

@hackingbutlegal
Created February 12, 2013 04:18
Show Gist options
  • Select an option

  • Save hackingbutlegal/4760213 to your computer and use it in GitHub Desktop.

Select an option

Save hackingbutlegal/4760213 to your computer and use it in GitHub Desktop.
Python web server
import SimpleHTTPServer, SocketServer, sys
#SET THE PORT VARIABLE TO COMMAND-LINE ARGUMENT
PORT = sys.argv[1]
def RunServer():
try:
httphandler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", int(PORT)), httphandler)
print "Python Web Server, serving at port" + PORT
httpd.serve_forever()
except (KeyboardInterrupt, SystemExit):
print "Exiting..."
sys.exit
except:
print "There was a problem starting the webserver at port " + PORT
RunServer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment