The command python -m simplehttpserver starts a simple HTTP server in Python 2 that serves files from the current directory.
However, this module was removed in Python 3.
For modern Python, you should use the http.server module instead.
1. Navigate to the desired directory: Open a terminal or command prompt and change your working directory to the one containing the files you want to serve.
2. Run the command: Execute the following command to start the server.
python3 -m http.server3. Specify a port (optional): By default, the server runs on port 8000. To use a different port, provide the number as an argument.
python3 -m http.server 80804. Access the server: Open a web browser and navigate to http://localhost:8000 (or the port number you specified). You will see a directory listing of the files you are serving.
4. Finding the IP of the server: In windows, to find the IP address, you can use ipconfig and for mac, you can use ifconfig | grep inet
- Not for production: Python's simple HTTP server is intended for development and file sharing on a local network. It lacks robust security features and is not suitable for public-facing or production environments.
- Data exposure: Be aware that running this command exposes all files and subdirectories in the working directory to anyone on the same network.
- Firewall: Whenyou launch it in a Windows PC, it may require you to allow permission through a firewall.
- HTTP and not HTTPS: When you download the files, let's say, on a phone, then you may get an error prompt advising you that the connection is not secure and download over https is not available.