How do I configure Python to execute CGI's/Py scripts? I'm at a loss in the new IIS manager - and don't even see the CGI-module. I reviewed the KB-article on using Python with IIS 5.0 (http://support.microsoft.com/kb/276494)
but can not find equivalent options in IIS 7.
You can add new Python CGI Script Map in IIS 7 management UI from:
"Features View" -> "Handler Mappings"
Here are the steps how I make Python running in IIS 7. Hope it helps:
1. Please make sure Python is installed properly.
2. Make sure CGI module is installed in IIS 7
Control Panel -> Programs -> Program and Features ->
Turn Windows features on and off -> Internet Information Services ->
World Wide Web Services -> Application Development Features ->
CGI module.
3. Add web application for Python, In IIS Manager, right click Default Web Site ->
Add Application, setting Alias e.g.: PythonApp, and make it pointing to some folder like C:\PythonApp, then click
OK
4. In Features View, open Handler Mappings, right click to
Add Script Map ...
5. In Request path, put "*.py" as the script files extension, In
Executable select "C:\Python25\Python.exe %s %s", here is my Python installation path and its parameters, this is mentioned in the KB article, you can check what are these two parameters used for. Then giving the script mapping an appropriate
Name, like Python. Click OK.
6. Create or copy a test.py into the virtual directory (C:\PythonApp), you can find it in the KB article.
7. In Browse View, right click browse to verify it.
Zhao Ji Ma
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
Following this setup, when I try a simple test file "test.py" I get the error below (note that the test file works under IIS 5.1 on my previous hardware, so I am comfortable that is OK..)
Python 3.0.1 and IIS 7 under Windows Server '08 by the way...
Thanks deeply, in advance, for any pointers...
Regards,
GREG...
-------------
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "".
You can get this information and more here there is also information on how to use FastCGI, and I recommend you check out Django as well and here is a online book to get you going.
I have exactly the same problem. I try to make Mercurial work on Windows 7. For that I need to make Python 3.1 works on IIS7. After following the instructions of
here and here I get the same error as you did! I wonder if you could solve the problem till now, probably you did:) can you or any one else tell me
what I do wrong?
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are ""
I was getting that error until I updated the mapping. initially i had just the python executable in the executable field, in fact you need an additional parameter:
Thanks to everyone contributing. The solution that I found is that the first line of the test script must print an empty line. HTML, HEAD and TITLE tags are not necessary. The explanation in
this Tutorial, which also has a working test script.
dirkhamstra
1 Post
Configuring Python on IIS 7
Jun 16, 2007 11:04 PM|LINK
Hi !
How do I configure Python to execute CGI's/Py scripts? I'm at a loss in the new IIS manager - and don't even see the CGI-module. I reviewed the KB-article on using Python with IIS 5.0 (http://support.microsoft.com/kb/276494) but can not find equivalent options in IIS 7.
Any pointers appreciated.
Thanks!
Zhao Ji Ma -...
765 Posts
Microsoft
Re: Configuring Python on IIS 7
Jun 19, 2007 09:29 AM|LINK
Hi,
You can add new Python CGI Script Map in IIS 7 management UI from:
"Features View" -> "Handler Mappings"
Here are the steps how I make Python running in IIS 7. Hope it helps:
1. Please make sure Python is installed properly.
2. Make sure CGI module is installed in IIS 7
Control Panel -> Programs -> Program and Features -> Turn Windows features on and off -> Internet Information Services -> World Wide Web Services -> Application Development Features -> CGI module.
3. Add web application for Python, In IIS Manager, right click Default Web Site -> Add Application, setting Alias e.g.: PythonApp, and make it pointing to some folder like C:\PythonApp, then click OK
4. In Features View, open Handler Mappings, right click to Add Script Map ...
5. In Request path, put "*.py" as the script files extension, In Executable select "C:\Python25\Python.exe %s %s", here is my Python installation path and its parameters, this is mentioned in the KB article, you can check what are these two parameters used for. Then giving the script mapping an appropriate Name, like Python. Click OK.
6. Create or copy a test.py into the virtual directory (C:\PythonApp), you can find it in the KB article.
7. In Browse View, right click browse to verify it.
Sincerely,
Microsoft Online Community Support
“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
scubak1w1
3 Posts
Re: Configuring Python on IIS 7
Apr 10, 2009 04:12 AM|LINK
Thank you for your reply...
Following this setup, when I try a simple test file "test.py" I get the error below (note that the test file works under IIS 5.1 on my previous hardware, so I am comfortable that is OK..)
Python 3.0.1 and IIS 7 under Windows Server '08 by the way...
Thanks deeply, in advance, for any pointers...
Regards,
GREG...
-------------
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "".
Module CgiModule
Notification ExecuteRequestHandler
Handler Python
Error Code 0x00000000
renato1
1 Post
Re: Configuring Python on IIS 7
May 10, 2009 02:57 AM|LINK
I also followed the instructions and having the same error:
HTTP Error 502.2 - Bad Gateway
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "".
If I changed the test to test.php and test.html and then it worked ok. So, it is not the test contents.
I already spend few hours on it without success... Any help would be appreciated!
Configuring Python on IIS 7 HTTP Error 502.2 - Bad Gateway
Mitchell Gee...
1 Post
Re: Configuring Python on IIS 7
Sep 10, 2009 04:25 PM|LINK
Hey there,
Basically IIS works now and has received a request from the CGI module but of course the response was not valid.
Try this in your *.py file:
IIS 7 cgi Django Fast Cgi Python
cecily
2 Posts
Re: Configuring Python on IIS 7
Jun 26, 2010 12:14 AM|LINK
Hello,
I tried to add Python Script Map in IIS7 in Windows 7, but failed. I followed those major procedures:
1) I added Script Map for the default web site:
Then you can see it has been added to this web site:
2) I created a a test.py into C:\inetpub\wwwroot
3) I tested http://localhost/test.py
I followed the instruction step by step. I do not know what the problem is.
Thanks a lot for any help !!
Boebele
1 Post
Re: Configuring Python on IIS 7
Oct 19, 2010 06:36 AM|LINK
Hello Cecily,
I have exactly the same problem. I try to make Mercurial work on Windows 7. For that I need to make Python 3.1 works on IIS7. After following the instructions of here and here I get the same error as you did! I wonder if you could solve the problem till now, probably you did:) can you or any one else tell me what I do wrong?
Thanks a lot in advance!!
kylefritz
1 Post
Re: Configuring Python on IIS 7
Dec 22, 2010 07:41 PM|LINK
I was getting that error until I updated the mapping. initially i had just the python executable in the executable field, in fact you need an additional parameter:
You're mapping should look like
Then my script worked:
IIS 7 Python 502.2 - Bad Gateway
Rbli
1 Post
Re: Configuring Python on IIS 7
Sep 13, 2011 10:04 AM|LINK