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?

Ian
  • 139
  • 3
  • 9
  • Instead of guessing, I suggest using the [Network Monitor](https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor) from the [Firefox Web Developer Tools](https://developer.mozilla.org/en/docs/Tools) to verify the headers. The shortcut is **Ctrl** + **Shift** + **Q**. – Cristian Ciupitu May 10 '14 at 18:09

1 Answers1

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
DerfK
  • 19,493
  • 2
  • 38
  • 54
  • 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: http://support.microsoft.com/kb/276494 – Ian May 10 '14 at 18:38