The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

python cgi scripts?

Discussion in 'General Discussion' started by oderland, Dec 5, 2003.

  1. oderland

    oderland Well-Known Member
    PartnerNOC

    Joined:
    Dec 30, 2002
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Kungsbacka, Sweden
    how do we let our users to use cgi scripts made in python ?
    Did a test but did not get any result in a browser .

    date.cgi

    #!/usr/bin/python
    #==============================================================#
    # Date and Time
    # Programmed by James Bekkema, email mail@tempestsw.com.
    # Copyright 2003, James Bekkema. No part of this code may be reused without permission.
    # See ReadMe file for more information
    #==============================================================#

    #=============EDIT HERE=============#
    # Select format to display the time/date:
    format = "%d/%m/%y, %H:%M"
    #=============STOP HERE=============#

    import cgi
    import time
    print "Content-Type: text/html\n"

    displayTime = time.strftime(format, time.gmtime(time.time() - time.timezone))

    print 'document.write("%s");\n' % displayTime

    ==========================================

    the url is:
    http://ehpc.se/date.py

    any clue?

    I can run this script i a shell btw

    //Jack:cool:
     
  2. dmuey

    dmuey Member

    Joined:
    Nov 25, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    It seems that apache is not configured to execute .py as a python script ( like .pl is executed as a Perl script).

    You would need to set up apache to do this. I actually have a thread asking about how to customize apache in a cpanel safe way.

    The thing that threw me off at first wast that you said at the top it was date.cgi bu the url is date.py! Anyway for the fatsest fix:
    - edit your httpd.conf to have .py executed as python scripts.
    - everytime you update apache make sure those changes are still there/ add them back

    HTH

    DMuey

    PS your Content type header probably needs 2 newlines at the end instead of one.
     
    #2 dmuey, Dec 29, 2003
    Last edited: Dec 29, 2003
  3. candrews

    candrews Registered

    Joined:
    Oct 8, 2003
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Denver
    Python version

    If you're using the same version of CPanel as my hosting service, you probably want your env line to look something like this:

    #! /usr/bin/env python2

    I found that there was both python 1.x and python 2.3.2 on the CPanel instal at my hosting provider.
     
  4. oderland

    oderland Well-Known Member
    PartnerNOC

    Joined:
    Dec 30, 2002
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Kungsbacka, Sweden

    sorry could not found the customize apache thread. Any idea how to mofify the apache config file?
     
  5. Jemshi

    Jemshi Well-Known Member

    Joined:
    Sep 11, 2003
    Messages:
    210
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    try moving that script to cgi-bin and then take it in browser.

    If not working, try adding

    AddHandler cgi-script .cgi .pl .py in an .htacess in your home dir and execute the script from there
     
  6. russellhosting

    russellhosting Active Member

    Joined:
    Jun 19, 2003
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    6
    Has anyone had any luck getting Python to execute as a cgi script with cPanel? I have tried all configurations and I still get a Internal Server Error.
     
Loading...

Share This Page