Haha! Run Python and iispython on IIS

Source: Internet
Author: User

Haha! Run Python and iispython on IIS

My company website gave me a headache. Under the guidance of many senior experts, a lot of CMD programs run well on the website, and hacker attacks are also good. I am exhausted only when the website and I are not good, the website is almost suspended...


To solve this problem, I thought of Python to solve it. But how to run Python on the website. I found a lot of information online. As a result, the problems are constantly emerging-all kinds of problems appear in front of me. I finally hit the answer when my manager watched me go crazy. In fact, the answer is as simple as the window paper. I remember when my father was a child, they had a song, "wash your feet, boil your winter melon feet, pear your bean curd, and wipe your ass and paste the window ".


Okay. Let's get down to the truth!


Er...


First, go to the official website to download the native Python 2.7. Why 2.7 is used? 3.xis not required. The reason is that 2.7 is relatively popular. In addition, many development programs are implemented on this basis. Moreover, 2.7 is similar to 3.X. Haha ...... Actually, I want to use it to compile QT...


We will first download it from the official website at https://www.python.org /.

Here, we download 2.7.8.





After downloading, double-click it. .



I chose all of them to save trouble. You can choose based on your own interests.



Install



After the installation, we open IIS. Here, because I use WIN7, you will be free to use other systems. In fact, it is basically the same. So don't worry too much. You use Win2003. I use Win2008. Is that swollen? In fact, there is no problem. Everyone is the same. It looks similar. Well, except for Linux and Unix. I will introduce it here on Windows.


In IIS, we choose to want a directory (my directory is called YANG-NOTEBOOK, and everyone should know what my surname is .).



Then, we enter the "ISAPI and CGI restrictions" in the window on the edge to perform operations (in fact, decentralization ).



In this "ISAPI and CGI restrictions", let's start to make minor moves-click "add ".



Enter the "path" here according to my own situation. Don't say it, you're lying to me. I was shocked by the east, the West, and the Great Cultural Revolution. You dare to lie to me. I will destroy you with a red skull ).

% S is added later. I didn't think about the specific reason. If everyone adds them, I will add them. Hahaha ......



Click "OK". Let's take a look at the results!



Click "OK" to go to the following options. Click "handler ing" as shown in my graph ".



After entering, click "add module ing" on the edge to add the module.



As mentioned above, you can copy the following content selectively (note that the "path" should be filled in according to your actual situation, and "% s" must be followed ).



Next, click "OK" and a prompt frame will pop up. Don't be confused here. Click "yes!



Okay. Let's see if the "python" We just created is in the bottom list!



Okay. The preparation is complete. IIS can directly support running Python! Now let's start writing code. Writing code is also required. For example, the following code:

#!/usr/bin/env pythonimport cgiprint "Content-Type: text/html\n"print "Hello World!!!"

I saved it as "show. py" and put it in the root directory of the website. Then I called it to see the result:



Yes, this is "Hello World ".


Note:

Import cgi # This is a package file and must be written. We can see that CGI is the best.

Print "Content-Type: text/html \ n" # This is also required. It seems that this is required by CGI. I don't know much about it.


If you do not write print "Content-Type: text/html \ n", the following results are displayed:



I have heard that many people have this problem and I don't know if it can be solved.


Well, this is how IIS runs the Python program. All about it!





Cgi written in python in IIS has an error.

Are you using python3? In 3, print is a function.

How to execute a Python script in IIS

For Active Server Pages (ASP) and simple Common Gateway Interface (CGI) scripts, IIS uses WindowsScriptingHost to parse VBScript and JScript. IIS can use other script interpreters. This article describes how to use Python as the scripting language to select CGI and ASP. Right-click the IIS manager "website" node, select "properties" main directory ", click" configuration ", and click" add "in" ing ", in the dialog box, set "executable file" to "/python.exe % s" and the extension to ". py, the action is "all actions", and then click OK. Can IIS parse py now? Compile a test. py file: print
Print 'status: 200 OK'
Print 'content-type: text/html 'printprint 'python Sample CGI'
Print''
Print 'this is a header'
Print ''# this is a comment
Print 'see this is just like most other HTML'

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.