Python uses commands to enable the http. server method, pythonhttp. server

Source: Internet
Author: User

Python uses commands to enable the http. server method, pythonhttp. server

Preface

If you urgently need a simple Web Server, but you do not want to download and install complex HTTP service programs, such as Apache and ISS. Then, Python may help you. Python can be used to complete a simple built-in HTTP server. Therefore, you can display your directories and files in HTTP mode. Compile only needs to do one thing, that is, install a Python.

If you are not familiar with installing python, refer to these two articles:

  • Python3.5 in win10 Environment
  • Install the latest Python 3.6 in Linux

After installation, you can start the text of this article.

Python uses commands to enable the http. server

If you want to use the command E: \ zpic as the download directory, then cd in cmd to this directory and execute the command:

python -m SimpleHTTPServer

The default port number is 8000. the root directory of the server is the working directory for running python commands.

If an error is prompted:

No module named SimpleHTTPServer

Try the following command:

python -m http.server

Use http: // 127.0.0.1: 8000 to access contents in the directory.

Or add the port number:python -m http.server  80

Use http: // 127.0.0.1 to access contents in the directory

Disable the server:

1) dos

Enter "ctrl + C" in the running interface to stop

2) python script

Port listening and related python processes need to be stopped

def stop_server(server)server.sorket.close()

======================================

The following three modules are used to build an http server:

1) BaseHTTPServer: provides basic Web services and processor classes, including HTTPServer and BaseHTTPRequestHandler;

2) SimpleHTTPServer: contains the SimpleHTTPRequestHandler class that executes GET and HEAD requests;

3) CGIHTTPServer: contains the CGIHTTPRequestHandler class for processing POST requests and execution.

Summary

The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.