Allen Pitts
asked on
Python on IIS
Hello Expert,
Working on getting Python to run from IIS
Following instructions from
http://stackoverflow.com/questions/6823316/python-on-iis-how
Basically the idea is
1. Unpack and install that python MSI. Choose the default, which puts python into c:\Python27
2. Create a directory to hold the "development" python scripts. Eg, c:\dev\python
3. Set the permissions on the files in the directory c:\dev\python to allow IIS to read and execute
4. Create a new IIS application. Specify the virtual path as /py and the physical path as c:\dev\python
5. Within the IIS application, add a script map for *.py, and map it to c:\python27\python.exe %s %s
6. Create a "HelloWorld.py" file in c:\dev\python with this as the content:
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
7. Invoke http://localhost/py/helloworld.py
When the helloworld.py is invoked the result is
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 "C:\Python27\python.exe: can't find '__main__' module in 'c:\\dev\\python' ".
Some articles on Python and 'CGI application misbehaved ' were read. One said to add
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/html\n\n\n";
another said add
#!c:/python26/python.exe
# original from http://python.about.com/od/cgiformswithpython/ss/test_cgi_all.htm
#
import sys
sys.stderr = sys.stdout
import os
from cgi import escape
Neither of these worked.
Any idea how to troubleshoot CGI or fix the problem?
Thanks
Allen in Dallas
Working on getting Python to run from IIS
Following instructions from
http://stackoverflow.com/questions/6823316/python-on-iis-how
Basically the idea is
1. Unpack and install that python MSI. Choose the default, which puts python into c:\Python27
2. Create a directory to hold the "development" python scripts. Eg, c:\dev\python
3. Set the permissions on the files in the directory c:\dev\python to allow IIS to read and execute
4. Create a new IIS application. Specify the virtual path as /py and the physical path as c:\dev\python
5. Within the IIS application, add a script map for *.py, and map it to c:\python27\python.exe %s %s
6. Create a "HelloWorld.py" file in c:\dev\python with this as the content:
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
7. Invoke http://localhost/py/helloworld.py
When the helloworld.py is invoked the result is
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 "C:\Python27\python.exe: can't find '__main__' module in 'c:\\dev\\python' ".
Some articles on Python and 'CGI application misbehaved ' were read. One said to add
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/html\n\n\n";
another said add
#!c:/python26/python.exe
# original from http://python.about.com/od/cgiformswithpython/ss/test_cgi_all.htm
#
import sys
sys.stderr = sys.stdout
import os
from cgi import escape
Neither of these worked.
Any idea how to troubleshoot CGI or fix the problem?
Thanks
Allen in Dallas
ASKER
Hello Baldwin,
I found the problem.
With the py application selected in IIS the Handler Mappings was clicked.
Right clicked on mapping called Python and chose Edit.
Noticed that the set instructions said that in 'Request Map'
the path should be *.py.
I left out the dot between the asterisk and the p.
So I got it to work.
I have used ASP, ASP.Net and JavaScript. In ASP the server
side script in an HTML page is included in tags like <% server script /%>
and in Javascript it is <SCRIPT>client script</SCRIPT>
How do you include Python in an HTML page?
If you want I can open another questions for this.
Thanks,
Allen in Dallas
I found the problem.
With the py application selected in IIS the Handler Mappings was clicked.
Right clicked on mapping called Python and chose Edit.
Noticed that the set instructions said that in 'Request Map'
the path should be *.py.
I left out the dot between the asterisk and the p.
So I got it to work.
I have used ASP, ASP.Net and JavaScript. In ASP the server
side script in an HTML page is included in tags like <% server script /%>
and in Javascript it is <SCRIPT>client script</SCRIPT>
How do you include Python in an HTML page?
If you want I can open another questions for this.
Thanks,
Allen in Dallas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
So the basic concept works but there is something blocking it in your setup. Have you added Python to your Path statement?