Need a quick HTTP server? Try Python on the #RaspberryPi

If you need to start up a quick-and-dirty HTTP server on the Pi, try the following at the command prompt:

python -m SimpleHTTPServer 8000

This will start up a server on port 8000. You can only server HTML pages without further work, but if you just want to stick something up quick, it’s a simple method.

You can also start up a server programmatically within Python:

import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.