Atirag
Atirag

Reputation: 1740

Make a python script work on IIS 8

I added this to the handler module on IIS for my website

Request Path: *.py
Executable: "C:\Program Files\Python 3.5\python.exe"
Name: Python

I gave permissions for the IIS user to this path C:\Program Files\Python 3.5\

I then made this test.py file to test my configuration

print("Content-Type: text/html")
print("")
print("""\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
""")

But then I got this Bad Gateway error when I try to load it by http://localhost/test.py

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:""

Any ideas what I am missing?

Upvotes: 0

Views: 2157

Answers (1)

Reut Sharabani
Reut Sharabani

Reputation: 31339

As shown in Microsoft's manual (described in more detail in the link):

  • Make sure that the Web site containing the Python scripts has an application set up
  • Verify that application mapping for .py files is set up
  • Verify that the file and directory permissions are set correctly in the computer's access control list (ACL).

And the test response (python 2, conversion should be easy enough):

print
print 'Status: 200 OK'
print 'Content-type: text/html'
print

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>'
print '<BODY>'
print '<H1>This is a header</H1>'

print '<p>' #this is a comment
print 'See this is just like most other HTML'
print '<br>'
print '</BODY>'

Seems like the Content-Length header is added for you and you should add a Status header.

Upvotes: 1

Related Questions