Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Windows run Python script's CGI mode in a browser?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "how Windows runs Python script's CGI mode in a browser". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Windows runs Python script's CGI mode in a browser.

The practice is:

Open httpd.conf, find "# scriptinterpretersource registry", and remove the previous comment # (if you can't find this line, add it yourself)

Find the word "options indexes followsymlinks" and add "execcgi" after it. (the "indexes" had better be removed, too, because if there is no index.html file under the directory, all the files in the directory list will be displayed, so there is a security vulnerability. If indexes is removed and there is no index.html file, a forbidden page will be displayed)

Find "addhandler cgi-script .cgi" and add .py after it. If you don't have this sentence, you can add "addhandler cgi-script .py" yourself.

Restart apache (sometimes restart will cause apache to die, so people in this situation can stop and then start)

Then create a test.py script

Print "content-type: text/html"

Print ""

Print ""

Print "hello world"

Print "pay attention to the second sentence print" can not be less, without this sentence, it will cause a "500internal server error" error.

Running the word http://localhost/test.py hello world in the browser indicates that it is working properly after it is output.

In addition, some error prompts are as follows:

Without adding scriptinterpretersource registry, a 500internal server error error will occur.

Without adding execcgi, 403 forbidden you don't have permission to access / test.py on this server will appear.

If addhandler cgi-script .py is not added, the content will be displayed in the browser as text text.

Note:

The intention of adding scriptinterpretersource registry is to let windows use registry to find the place where python is installed.

Execcgi allows python script to run in any directory, because apache defaults to letting cgi script run in the cgi-bin directory. When I put test.py under htdocs, there will be a problem of 403 forbidden. So you need to add execcgi so that you can run. Py script under htdocs. But there will be security vulnerabilities in excecgi. It's safer to use fastcgi. But only if fastcgi is installed.

Cgi mode is slower than mod_python mode. So try mod_python mode on other computers in the future.

At this point, I believe you have a deeper understanding of "how Windows runs Python script's CGI mode in the browser". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report