Skip to content

Instantly share code, notes, and snippets.

@ThomasChiroux
Created September 26, 2012 09:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ThomasChiroux/3786940 to your computer and use it in GitHub Desktop.
Save ThomasChiroux/3786940 to your computer and use it in GitHub Desktop.
python2 and python3 compliant simple http server
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""launch small http server
"""
import sys
try:
from SimpleHTTPServer import SimpleHTTPRequestHandler
except ImportError:
from http.server import SimpleHTTPRequestHandler
try:
from SocketServer import TCPServer as HTTPServer
except ImportError:
from http.server import HTTPServer
# simple web server
# serves files relative to the current directory.
server_port = 8000
try:
server_port = int(sys.argv[1])
except:
pass
httpd = HTTPServer(("", server_port), SimpleHTTPRequestHandler)
print("serving at port {0}".format(server_port))
httpd.serve_forever()
@RenatoXSR
Copy link

That's it! Perfect! Thank you very much.

@tianhuil
Copy link

tianhuil commented Sep 9, 2018

Thanks! I needed this. For a server that requires authentication, check out https://github.com/tianhuil/SimpleHTTPAuthServer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment