Equivalent of “python -m SimpleHTTPServer” in Python 3

I generally write tutorials on fixing coding errors, but I would not consider it like that.

This is going to be a short post as the answer is a single line prompt.

python3 -m http.server

In Python 3.0, the SimpleHTTPServer module was integrated into the http.server module. When you use the 2to3 tool to upgrade your code to Python 3.0, it will automatically update the imports for you.

Your command should be python -m http.server. Depending on how Python is installed on your system, you might need to use python3 -m http.server instead.

In Python 3.3, you should use python3 -m http.server --cgi as the alternative to the older python -m CGIHTTPServer command.

To target a specific interface rather than all interfaces, you can use the -b or --bind flag. For instance, using the command python -m http.server 8000 --bind 127.0.0.1 will do just that. Here, 8000 represents the port number, while 80 is typically used as the standard port for HTTP communications.

Leave a Comment

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

Scroll to Top