Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python, IIS 5.0 and CGI 1

Status
Not open for further replies.

Lozbinator

Programmer
Jan 13, 2003
50
AU
Hello All!

I am trying to setup my local install of IIS to test the use of python for CGI scripts. I have read around on the net and found instructions to setup IIS to deal with this, but despite following instructions it seems to only want to print the code to the screen rather than process the cgi file.

If anybody has any suggestions they would be most appreciated.

- Lauren.
 
Hello.
I don't know much about IIS, but I can barely remember that somewhere in the IIS configuration you can specify the extensions which must be considered executable.
Try to turn this option ON for .py/.pyc files.
 
Hi sebsauvage,

Thanks for replying (again!)

I've tried to configure IIS for .cgi extensions (naming my python cgi scripts with a .cgi extension) and pointing IIS to python.exe.

Perhaps this is wrong??
 
Well I think it's ok as long as the user has the right to execute scripts on the directory where cgi are located.
(see directory or site properties).

To test, try the following CGI:
[tt]print "Content-Type: text/html"
print
print "Hello world !"[/tt]

It should display a single "Hello world !".

(Dont forget the [tt]import cgitb;cgitb.enable()[/tt] trick to debug your CGI, or you will never see errors in Python CGI.)
 
Usually you write Python CGI this way:

[tt]import cgi
form = cgi.FieldStorage()
if form.has_key["login"]:
...
[/tt]

But if an error occurs in your Python script, you will not see the error (Python writes errors to stderr, but the webserver expects CGI output in stdout).

[tt]import cgitb;cgitb.enable()[/tt] will force Python to output an HTML to stdout in case of error. You will be able to see the errors, the stack, etc.
Once your CGI is debugged and ready for production, don't forget to remove this line !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top