?
Solved

Python on IIS

Posted on 2015-01-14
3
Medium Priority
?
510 Views
Last Modified: 2015-01-14
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
0
Comment
Question by:9apit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40549719
I have Python in a directory outside the web root.  So I added it as a 'Virtual Directory' and copied your HelloWorld.py and it ran just fine.  I already had Python set up.  I am running IIS 5.1 (XP) and Python 2.7.  IIS 5.1 is simpler than the ones that follow.

So the basic concept works but there is something blocking it in your setup.  Have you added Python to your Path statement?
0
 

Author Comment

by:9apit
ID: 40549771
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
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40549797
How do you include Python in an HTML page?
I've never seen it done that way.  Python, like Perl, is usually used to create a web page thru 'print' statements.  I don't know of a way to 'embed' it in a web / HTML page.

In my IIS, the mapping is '.py', with the dot and without the star '*'.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question