1

I am trying to get Python working with IIS 7.5.

I have added a script handler for Python:

Python Script Map Handler

Python itself doesn't seem to be the problem. I have ran scripts on the command line with no problem. The script I am using to test Python functionality is below:

print
print 'HTTP/1.0 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>'

The problem is that IIS seems to be setting the HTTP content-type header to text/plain before the python script is executed, because when I browse to the python script in my browser, I get this output:

test.py browser output

What am I doing wrong, and how can I fix this?

1
2

There should be nothing at all printed before the header.

eg your program should start with:

print 'HTTP/1.0 Status: 200 OK'
print 'Content-type: text/html'
print
2
  • 1
    Also to make it more portable and avoid any issues with line endings on other operating systems, sys.stdout.write('HTTP/1.0 Status: 200 OK\r\nContent-type: text/html\r\n') should be used. – Cristian Ciupitu May 10 '14 at 17:59
  • What's interesting is that I got my example from the Microsoft Knowledgebase: support.microsoft.com/kb/276494 – Ian May 10 '14 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.