1

I have this test python file

import os

print 'Content-type: text/html' 
print 

print '<HTML><HEAD><TITLE>Python Sample CGI</TITLE></HEAD>'
print '<BODY>'
print "<H1>This is A Sample Python CGI Script</H1>"
print '<br>'
if os.environ.has_key('REMOTE_HOST'):
   print "<p>You have accessed this site from IP: "+os.environ["REMOTE_HOST"]+"</p>"
else:
   print os.environ['COMPUTERNAME']

print '</BODY></html>'

I created an application on IIS 5.1 with permission to execute scripts and created a mapping to .py like this:

C:\Python30\python.exe -u "%" "%"

But when I try to execute the script I got the following error:

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

C:\Python30\python.exe: can't find '__main__.py' in ''

Any idea?

Seibar
  • 68,705
  • 38
  • 88
  • 99
Paul
  • 12,359
  • 20
  • 64
  • 101

1 Answers1

2
C:\Python30\python.exe -u "%" "%"

Close, but it should be "%s". I use:

"C:\Python30\python.exe" -u "%s" 

(The second %s is for command-line <isindex> queries, which will never happen in this century.)

bobince
  • 528,062
  • 107
  • 651
  • 834
  • Thanks... But now I got other error: CGI Error File "c:\inetpub\wwwroot\geoserver\python.py", line 2 print 'Content-type: text/html' ^ SyntaxError: invalid syntax – Paul Apr 08 '09 at 15:49
  • print is a function under Python 3.0. If you're sure you want to use Python 3.0 for webdev (it's a very rocky area right now; many tools and libraries aren't ready for 3.0), then in CGI you'll need to say “print('Content-type: text/html')” with the parentheses. – bobince Apr 08 '09 at 17:09