[Tutor] CGI File Woes
noufal at airtelbroadband.in
Sun Sep 30 19:58:22 CEST 2007
> Hello all,
> I am working on a very simple CGI script. The site I want to use it
> on is a shared linux host, but I confirmed that .py files in the
> right dir with the right permissions and shebang execute just fine,
> Hello World sort of tests were successful.
Those are the first things I'd try too.
> So now something a little more involved:
> import cgitb; cgitb.enable()
> thefile = open("template.html", "r")
> templatestuff = thefile.read()
> print "Content-Type: text/html"
> if templatestuff:
> print "Found it"
> title1 = "I am a title!"
> body1 = "I am some hot content"
> print templatestuff % (title1, body1)
> "template.html" is in the same dir, and is simply:
> <title> %s </title>
> Any ideas?
Here are a few ideas plus some suggestions. I've been dabbling with
python/cgi myself and so there might be something you can take from
- If your webserver and the machine where you executed this from are
different (home directories are NFS mounts etc.), then the permissions
and directory visibilities might affect things.
- It looks fairly obvious that the problem is in those three lines. Your
content-type header is printed only after those lines are executed so
if there is an error there, you'll get an error 500. Try putting your
content-type line right after your import cgitb.
- Wrap the 3 suspicious lines in a try block and print out the execption
which you catch.
- Tail the server logs to see what happened.
More information about the Tutor