Go The construction and operation of Python Web simple server

Source: Internet
Author: User

Python Web simple server build and run Python 3 server build is configured environment variables, in DOS CD to the project directory, input: python-m http.server--cgi 8080 Below is I encountered in the construction process problems and solutions Method: 1, according to Http://www.cnblogs.com/xuxn/archive/2011/02/14/build-simple-web-server-with-python.html, the establishment of a simple Web server, the specific following:

A simple Web server can be built using Python's own package. In DOS CD to prepare to do the server root directory under the path, enter the command:

    • PYTHON-M Web server module [port number, default 8000]
For example:
    • Python-m simplehttpserver 8080

Then you can enter it in the browser

    • http://localhost: Port Number/path
To access server resources.
For example:
    • Http://localhost:8080/index.htm (of course index.htm files have to be created yourself)
Other machines can also be accessed via the server's IP address.

There are three types of "Web server modules" here:

    • Basehttpserver: Provides basic Web services and processor classes, respectively, Httpserver and Basehttprequesthandler.
    • Simplehttpserver: Contains the Simplehttprequesthandler class that performs the get and head requests.
    • Cgihttpserver: Contains the processing post request and executes the Cgihttprequesthandler class.
2, according to the above operation after the problem: ' Python ' is not an internal or external command this is because the environment variable is not configured, the configuration is as follows: computer-Right-click-Properties, and then found in the left column advanced system settings-environment variables, in the system variables found path, And then add your path to the Python installation, for example, my is appended to the following:;D: \python33 3, as described above and then appear: No module named Cgihttpserver this reason is mainly said that the method of establishing the server is for Python 2x, as mentioned in http://my.oschina.net/hevakelcj/blog/373830:

In the Python2.6 version, the/usr/bin/lib/python2.6/directory will have basehttpserver.py, simplehttpserver.py, cgihttpserver.py

But in the Python3.4, there is no above 3 files, but close to the/usr/bin/python3.4/http/server.py file.

The command to start the CGI service in python2.6 is:

    • Python-mcgihttpserver 8080
In the python3.4, it is:
    • Python3.4-m http/server--cgi 8080

The port number is an optional parameter.

4, do not know whether the above content is written in the problem or because my Python version is 3.3.5, so use the above command will be reported to No module Namedhttp/server, re-modify the following can be

Python-m http.server--cgi 8080

5, at run time need to copy the program to prepare to do the server root directory

Go The construction and operation of Python Web simple server

Related Article

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.