tags:

views:

664

answers:

1

Hello, 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?

+2  A: 
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
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
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