Jun 17, 2007 12:04 AM|dirkhamstra|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 () but can not find equivalent options in IIS 7.
Any pointers appreciated.
Thanks!
Jun 19, 2007 10:29 AM|Zhao Ji Ma - MSFT|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.
Apr 10, 2009 05:12 AM|scubak1w1|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
May 10, 2009 03:57 AM|renato1|LINK
I also followed the instructions and having the same error:
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
Sep 10, 2009 05:25 PM|Mitchell Geere|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:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print "Hello World!"
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.
IIS 7 cgi Django Fast Cgi Python
Jun 26, 2010 01:14 AM|cecily|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
from Http import *
def Request():
Header("Content-type: text/html")
Write("Hello, World!")
3) I tested
I followed the instruction step by step. I do not know what the problem is.
Thanks a lot for any help !!
Oct 19, 2010 07:36 AM|Boebele|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!!
Dec 22, 2010 08:41 PM|kylefritz|LINK
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:
You're mapping should look like
Then my script worked:
print "Status: 200 OK" print "Content-Type: text/plain;charset=utf-8" print print "Hello World!"
IIS 7 Python 502.2 - Bad Gateway
Sep 13, 2011 11:04 AM|Rbli|LINK
Oct 31, 2013 06:59 PM|aj_s|LINK
I had the same issue, please verify that the web.config should be something like this... I had some extra character in path value.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="cgi-bin" path="*.py" verb="*" modules="CgiModule" scriptProcessor="J:\Python27\python.exe %s %s" resourceType="Unspecified" /> </handlers> </system.webServer> </configuration>
9 replies
Last post Oct 31, 2013 06:59 PM by aj_s