Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    3

    Default Just trying to get Python CGI to work!

    I had read this thread:

    http://forums.westhost.com/showthrea...ghlight=python

    but it may be out of date, when I made such changes to my httpd.conf file, it crashed my appache, and I needed tech support to help me re-start it.

    At this point, all I want is a working "Hello World". for an index.py file.

    I have chmod 755, and set options ExecCGI in my .htaccess but I'm still getting the helpless "Internal Server Error".

    Due to my working life, I've become more comfortanly in Python than PHP, but if I have to, I'll learn PHP.

    Python works fine when I connect via ssh, so it's installed. But I can't get appache to swallow it.

    it's a pitty though, I just love using regex in Python.
    Last edited by woolhiser; 07-17-2009 at 05:09 PM.

  2. #2
    Junior Member
    Join Date
    Jul 2009
    Posts
    3

    Default OK one step at a time

    The first thing to do was to get the shell to run in ssh using PuTTY.

    Code:
    #! /usr/bin/env python
    print "<HTML><BODY>Hello World!</BODY></HTML>"
    Well this wouldn't work from the shell, because oddly enough, "." was not in my path!

    so :
    Code:
    $ export PATH=.:$PATH
    helps and now my script runs in the shell.

    There was some discussion about #! /user/bin/env python, but this standard path is working for me. Anyway, I thought I'd pass that along as I try to get the simplest of things to work.

    I'm still getting an internal server error from apache, but now I know that the script should work provided apache is configured correctly (which it apparently isn't)

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    3

    Default Thanks for all the help!

    Just kidding, but I have the solution for Python scripting.

    It helps a lot if you read your error log found in /var/log/httpd . And there it told me exactly what was wrong!

    But here's all anyone needs to do:

    1) install your python using the site manager
    2) in the directory where you run your python, be sure to add a .htaccess file and include:
    Code:
    options ExecCGI
    3) create you file such as index.py:
    Code:
    #! /usr/bin/env python
    
    print "Content-Type: text/html\n\n"
    print "<HTML><BODY>Hello world!</BODY></HTML>"
    Here, it was important to have the content type header. When I had read the /var/log/httpd/error_log, it clearly stated that the header was malformed. In addition, it received "<HTML><BODY> ..." as the header which told me that in fact, Apache was executing python, and the script was working, but the script was not producing a valid header.

    4) Be sure to chmod 755 index.py . You must make your script executable.

    And that's really all there is!

  4. #4
    Junior Member
    Join Date
    Apr 2009
    Posts
    5

    Default

    Quote Originally Posted by woolhiser View Post
    Just kidding, but I have the solution for Python scripting.

    It helps a lot if you read your error log found in /var/log/httpd . And there it told me exactly what was wrong!

    But here's all anyone needs to do:

    1) install your python using the site manager
    2) in the directory where you run your python, be sure to add a .htaccess file and include:
    Code:
    options ExecCGI
    3) create you file such as index.py:
    Code:
    #! /usr/bin/env python
    
    print "Content-Type: text/html\n\n"
    print "<HTML><BODY>Hello world!</BODY></HTML>"
    Here, it was important to have the content type header. When I had read the /var/log/httpd/error_log, it clearly stated that the header was malformed. In addition, it received "<HTML><BODY> ..." as the header which told me that in fact, Apache was executing python, and the script was working, but the script was not producing a valid header.

    4) Be sure to chmod 755 index.py . You must make your script executable.

    And that's really all there is!
    I followed the instructions listed and was able to get things working for one folder in the www branch but not the opt branch. Checked all the settings and seems ok but the Python program doesn't get executed - just listed. Works if I move it to under www. Don't understand why.

  5. #5
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    I think the issue is the #2 step.
    2) in the directory where you run your python, be sure to add a .htaccess file and include:
    You need to also add that .htaccess file to the directory you are placing the python file in. Did you do that? The reason it works in www is because the options ExecCGI is set in the httpd.conf file for that directory.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •