Solved

Python on IIS

Posted on 2015-01-14
3
464 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

696 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