Solved

Python on IIS

Posted on 2015-01-14
3
388 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
  • 2
3 Comments
 
LVL 83

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 83

Accepted Solution

by:
Dave Baldwin earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now