I know there have been several posts concerning Python and CGI / HTML, but I can't get my little script to even print a web page.

#!/usr/bin/python
print "Content-Type: text/html\n\n"
print
import sys
sys.stderr = sys.stdout
import cgitb; cgitb.enable(display=0, logdir=".")
print """
<html>
<body>
<div align="center"><font style="font-family:verdana; font-size:18px">Hello from Python</font></div>
<br>
Goodbye.
</body>
</html>"""

I get a '500 server error' when I try to run this through a web server, but it runs without errors on my command line.

The file permissions are rwxr-xr-x.

I've posted in comp.lang.python but haven't found a solution there.

The script does not create a log file in the current directory either.

Can someone here point out why this may not be working?

You may need \r\n at the end of your lines instead of just \n.

Have you looked into PyWeb, which is designed to do what you want? I can't speak to how well it does what you want, but surely it merits a look.

You may need \r\n at the end of your lines instead of just \n.

Have you looked into PyWeb, which is designed to do what you want? I can't speak to how well it does what you want, but surely it merits a look.

Thanks for the reply. I tried your suggestion, but same results. Even removed them completely from the print statement.

The solution to my problem of not being able to execute a simple Python script on my hosting server is slightly embarrassing. It seems that while Python itself is installed, the Apache module needed to make it available through a web server is not. DUH!

This only came about after some digging on my part, and eventually I talked with one of the techs at the server farm.

The good news is that I did get it to work on my home PC, after putting the right path in the shebang line. Another slight embarrassment. Ah well, who says old dogs can't learn new tricks.

Good to hear things are working.

What's the name of the Apache module and where did you find it? I may be trying to do the same thing in a couple of months.

Good to hear things are working.

What's the name of the Apache module and where did you find it? I may be trying to do the same thing in a couple of months.

I didn't need to add any modules to my home PC - once I had the right path to Python in my script, it worked fine. Just make sure it goes in or under cgi-bin or whatever you have for executables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.