|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
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()
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. |
|
#2
|
||||
|
||||
|
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 Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
||||
|
||||
|
If I do, I have no clue how to access them...
Where does Apache place its server logs ? I'll look for them. |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
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() |
|
#6
|
||||
|
||||
|
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> ![]() 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 ![]() |
|
#7
|
|||
|
|||
|
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. |
|
#8
|
||||
|
||||
|
>> 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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Yet another CGI thread... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|