Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 28th, 2004, 01:08 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
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.

Reply With Quote
  #2  
Old February 28th, 2004, 01:40 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 1 m 11 sec
Reputation Power: 4080
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

Reply With Quote
  #3  
Old February 28th, 2004, 01:42 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
If I do, I have no clue how to access them...

Where does Apache place its server logs ? I'll look for them.

Reply With Quote
  #4  
Old February 28th, 2004, 01:48 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 1 m 11 sec
Reputation Power: 4080
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.

Reply With Quote
  #5  
Old February 28th, 2004, 04:03 PM
ilves ilves is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Norway
Posts: 41 ilves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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()

Reply With Quote
  #6  
Old February 28th, 2004, 04:33 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
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

Reply With Quote
  #7  
Old February 28th, 2004, 04:38 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
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.

Reply With Quote
  #8  
Old February 29th, 2004, 04:16 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,389 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 1 m 11 sec
Reputation Power: 4080
>> 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Yet another CGI thread...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap