The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Yet another CGI thread...
Discuss Yet another CGI thread... in the Python Programming forum on Dev Shed. Yet another CGI thread... Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 28th, 2004, 01:08 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
|
Yet another CGI thread...
First, look at my code. Please ?
Code:
#!/usr/bin/python
import cgi,cgitb,sys ; sys.stderr = sys.stdout ; cgitb.enable()
def haut():
print """<html>
<head>
<title>Malvenue sur mon site...</title>
</head>
<body bgcolor="#040404" text="grey">
<center><img src="entete.png"></center>"""
def cadres(f):
print '<frameset rows="10%,90%" frameborder=no border=0 framespacing=0>'
print '<frame name="cadregauche" frameborder=no border=0 framespacing=0>'
print '<a href="bg.txt">BG</a><br>'
print '<frame name="main" frameborder=no border=0 framespacing=0 src="',f,'">'
def bas():
print "</frameset>"
print '<p><p><center><A href="http://www.kraland.org/" target="_top">'
print '<img src="http://www.kraland.org/kraland.gif" border=0></A><br>'
print "Votre navigateur n'affiche pas le logo du haut de façon transparente ? La raison : votre navigateur ne vaut pas un clou.<br>"
print '<a href="http://www.mozilla.org/products/firefox">Mozilla Firefox. Le seul vrai.</a></center>'
print '</body></html>'
form = cgi.FieldStorage()
print "Content-Type: text/html\n"
haut()
if form.has_key("page"):
f = str(form.getvalue("page"))+'.html'
else:
f = "bg.html"
cadres(f)
bas()
I know it's in french ; it doesn't matter. Look at the HTML and Python code, please. Something's wrong with this code : ran in my Python interpreter, I receive good ouptut bout, once uploaded on my website and CHMODed, I only get 500 errors. What could be wrong ?
EDIT : another question : does the script need to be renamed to .cgi or could I leave it at .py ? Just wondering.
__________________
Time is the greatest of teachers ; sadly, it kills all of its students.
- Hector Berlioz
Last edited by SolarBear : February 28th, 2004 at 01:13 PM.
|

February 28th, 2004, 01:40 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
The 500 error could be due to quite a few things actually. Do you have access to your web server's error logs?
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
|

February 28th, 2004, 01:42 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
|
If I do, I have no clue how to access them...
Where does Apache place its server logs ? I'll look for them.
|

February 28th, 2004, 01:48 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
The location of the logs depends on the operating system (and also the person who installed the webserver  ), so you'll need to let us know what you're using. First, please answer the following:
1. Is this your webserver, or does it belong to some hosting company?
2. Is the webserver configured to use python in the first place? Some hosting companies offer python, but a majority of them don't do this.
3. Have you actually got a simple "hello world" type program written in python to work on the webserver before, or is this the first attempt to get a python program running on it? If this is the first program you're trying on the webserver, see point 2.
Last edited by Scorpions4ever : February 28th, 2004 at 01:50 PM.
|

February 28th, 2004, 04:03 PM
|
|
Contributing User
|
|
Join Date: May 2003
Location: Norway
Posts: 41
Time spent in forums: 3 h 52 m 22 sec
Reputation Power: 10
|
|
If your web server is not set up to treat .py files as cgi scripts it will normally treat the file as plain text, and just output the code.
To test your installation, try this script
Code:
#!/path/to/python
import cgi
cgi.test()
|

February 28th, 2004, 04:33 PM
|
 |
onCsdfeu
|
|
Join Date: Jul 2003
Location: Canada
Posts: 100
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
|
|
Ok...
1. Is this your webserver, or does it belong to some hosting company?
-> It's not mine, I'm hosted at rootr.com. They use OpenBSD as operating system and have Python 2.2 installed and working.
2. Is the webserver configured to use python in the first place? Some hosting companies offer python, but a majority of them don't do this.
-> This'll answer ilves' question too : yep, it does. I've succesfully wrote CGI scripts on this server and they ran fine. Here's one : http://solarbear.rootr.com/gap/gap.cgi .The obscenely simple
Code:
#!/usr/bin/python
import cgi
print 'Content-Type: text/html\n'
print <html>moo</html>
doesn't even work. I'm really confused. And I DON'T wanna resort to Perl.
3. Have you actually got a simple "hello world" type program written in python to work on the webserver before, or is this the first attempt to get a python program running on it? If this is the first program you're trying on the webserver, see point 2.
-> See point 2 
|

February 28th, 2004, 04:38 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
|
One possible cause is if python is not installed where you think it is - on many systems it is in /usr/local/bin/python instead of /usr/bin/python. On some systems #! /usr/bin/env python will work too. Read the comment block at the start of cgi.py in the standard library.
If you can get a server shell prompt, either directly or through telnet/SSH, then typing which python will tell you where python is installed (if at all). Otherwise ask your service provider, or try playing around with variations of the above.
Dave - The Developers' Coach
Last edited by DevCoach : February 28th, 2004 at 04:44 PM.
|

February 29th, 2004, 04:16 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
>> They use OpenBSD as operating system
There's your problem. OpenBSD doesn't include python in the base system. So if your hosting company provides python, they must have installed it separately (possibly from the OpenBSD ports system) and the location is almost certainly /usr/local/bin/python instead of /usr/bin/python (Sidenote for all *NIX neophytes -- the /usr/local tree is meant to be used for software that is not present in the standard installation and is installed by the sysadmin separately).
Your best bet would be to begin your code with:
#!/usr/bin/env python
This will cause it to work in both your local machine as well as the webhost, because /usr/bin/env is present on just about every flavour of *nix.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|