User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,472 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,795 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1017 | Replies: 5 | Solved
Reply
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Generating HTML in Python

  #1  
Sep 13th, 2007
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?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Posts: 268
Reputation: BearofNH is on a distinguished road 
Rep Power: 2
Solved Threads: 19
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz in Training

Re: Generating HTML in Python

  #2  
Sep 13th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Generating HTML in Python

  #3  
Sep 13th, 2007
Originally Posted by BearofNH View Post
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.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Generating HTML in Python

  #4  
Sep 14th, 2007
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.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: May 2007
Posts: 268
Reputation: BearofNH is on a distinguished road 
Rep Power: 2
Solved Threads: 19
BearofNH's Avatar
BearofNH BearofNH is offline Offline
Posting Whiz in Training

Re: Generating HTML in Python

  #5  
Sep 14th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Generating HTML in Python

  #6  
Sep 14th, 2007
Originally Posted by BearofNH View Post
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.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 2:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC