[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Python on IIS

Posted on 2015-01-14
3
Medium Priority
?
568 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:Allen Pitts
[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:Allen Pitts
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
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 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…

650 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