The http.server module

In this section, we are going to learn about a module from the http package, the http.server module. This module defines the classes used for implementing HTTP servers. It has two methods: GET and HEAD. By using this module, we can share files over a network. You can run the http server on any port. Make sure the port number is greater than 1024. The default port number is 8000.

You can use http.server as follows.

First, navigate to your desired directory and run the following command:

student@ubuntu:~/Desktop$ python3 -m http.server 9000

Now open your browser and write localhost:9000 in your address bar and press Enter. You will get the output following:

student@ubuntu:~/Desktop$ python3 -m http.server 9000
Serving HTTP on 0.0.0.0 port 9000 (http://0.0.0.0:9000/) ...
127.0.0.1 - - [23/Nov/2018 16:08:14] code 404, message File not found
127.0.0.1 - - [23/Nov/2018 16:08:14] "GET /Downloads/ HTTP/1.1" 404 -
127.0.0.1 - - [23/Nov/2018 16:08:14] code 404, message File not found
127.0.0.1 - - [23/Nov/2018 16:08:14] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [23/Nov/2018 16:08:21] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [23/Nov/2018 16:08:21] code 404, message File not found
127.0.0.1 - - [23/Nov/2018 16:08:21] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [23/Nov/2018 16:08:26] "GET /hello/ HTTP/1.1" 200 -
127.0.0.1 - - [23/Nov/2018 16:08:26] code 404, message File not found
127.0.0.1 - - [23/Nov/2018 16:08:26] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [23/Nov/2018 16:08:27] code 404, message File not found
127.0.0.1 - - [23/Nov/2018 16:08:27] "GET /favicon.ico HTTP/1.1" 404 -
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset