Python SimpleHTTPServer
In this article, you will learn about the Python SimpleHTTPServer module.
The HTTP communicates between two entities: sender and receiver. The sender sends a message to the receiver. The receiver receives the message, processes it, and generates the response. A protocol is a standard arrangement of rules that encourages fruitful correspondence between electronic gadgets. These arrangements of commonly acknowledged and actualized rules incorporate the orders used to start the sending and gathering of information, the information types to be communicated between gadgets, how to distinguish blunders in information, how fruitful information moves are affirmed, and significantly more. The parts of message it contains are - URL, GET, POST, BODY, Headers and Status code.
Python provides the SimpleHTTPServer module which supports only two HTTP methods - GET and HEAD. This module can make the most of our task easy in our daily life.
Assume you and your colleague are utilizing the same local network. You have a few documents that you need to share with your colleague. However, both of you have a convenient hard disk, so you can duplicate those documents to that versatile hard disk and offer it to your colleague. At that point, Python SimpleHTTPServer can help you in this situation.
By using SimpleHTTPServer, you can easily share data on the same network.
Python SimpleHTTPServer Example
Suppose you want to share some folder or directory to your colleague. So simply, open your terminal window and go to that directory. For example, if you wish to share a directory '/python37/Scripts/projects/school', then the command will be the following.
Python 2
(env) c:\python37\Scripts\projects>cd school
(env) c:\python37\Scripts\projects\school>python -m SimpleHTTPServer 8080
Python 3
The Python SimpleHTTPServer module was merged into the http.server module in Python 3.
(env) c:\python37\Scripts\projects>cd school
(env) c:\python37\Scripts\projects\school>python -m http.server 8080
Then open your favorite browser and type localhost:8080, you will get the listed directory. For sharing to your colleague, replace localhost with your IP address and then share it with your colleague. You can also change the port to something else.
Related Articles
Vader Sentiment Analysis Python
isalpha Python
Python YouTube Downloader Script
Python project ideas for beginners
Pandas string to datetime
Fillna Pandas Example
Lemmatization nltk
How to generate QR Code in Python using PyQRCode
OpenCV and OCR Python
PHP code to send SMS to mobile from website
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml
Convert Python list to numpy array
Convert string to list Python
Python program to list even and odd numbers of a list
Python loop through list
Sort list in descending order Python
Convert array to list Python
Python take screenshot of specific window