#1
  1. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12

    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.
    Last edited by SolarBear; February 28th, 2004 at 02:13 PM.
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    If I do, I have no clue how to access them...

    Where does Apache place its server logs ? I'll look for them.
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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 02:50 PM.
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Norway
    Posts
    41
    Rep Power
    12
    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()
  10. #6
  11. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    12
    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
    Time is the greatest of teachers ; sadly, it kills all of its students.
    - Hector Berlioz
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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 05:44 PM.
  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    >> 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.
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo