How To Run and Use Simple HTTP Server In Python2 and Python3?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-run-and-use-simple-http-server-in-python2-and-python3/
PINTEREST
PINTEREST
INSTAGRAM

Python provides different HTTP and related modules in builtin and 3rd party modules. Python also provides some basic HTTP server modules native. In this tutorial we will learn how to run HTTP server in Python2 and Python3.

SimpleHTTPServer In Python2 From Commandline

We will use SimpleHTTPServer module for Python2. We will just provide the module name the port number we want to run HTTP server from commandline. In this example we will run from 8000 .

SimpleHTTPServer In Python2 From Commandline
SimpleHTTPServer In Python2 From Commandline

This screenshot means web server is listening from all network interfaces for TCP port 8000 for our HTTP web server.

SimpleHTTPServer In Python2 As Code

More complete way to run a HTTP server is running a web server script. We will use following code which is named webserver.py .

AND run like below.

SimpleHTTPServer In Python2 As Code
SimpleHTTPServer In Python2 As Code

SimpleHTTPServer In Python3 From Commandline

As Python version 3 the name of the HTTP server is changed to the http.server . So we need to run following command from command line.

SimpleHTTPServer In Python3 From Commandline
SimpleHTTPServer In Python3 From Commandline

We can see from output that all network interfaces are listening port 8000 with HTTP protocol.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-run-and-use-simple-http-server-in-python2-and-python3/
PINTEREST
PINTEREST
INSTAGRAM
LEARN MORE  Introduction to Javascript Programming Language