problem adding custom module in cgi script

Discussion in 'Python' started by bobicanprogram, Dec 12, 2008.

  1. Problem:

    Apache server serving an HTML file to a Firefox Browser containing a
    form and
    a CGI python CGI script. HTML works fine, meat of the CGI script works
    fine
    except that when a home grown and ordinarily functional module that is
    to be
    imported is added, the interpreter cannot find it.

    Running cgi.test() reveals that PYTHONPATH is correctly set. Still
    nada.
    Adding the sys.* stuff still nada.

    Items: Firefox Browser, Apache server, Python 2.5.

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

    The CGI script:
    #! /usr/bin/python

    import cgi
    #cgi.test()
    import sys

    #sys.path.append("/myModulePath")
    #sys.path.insert(0, "/myModulePath")
    import myModule **************** Problem here ********************

    ===========================================
    httpd error_log excerpt:
    [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] Traceback
    (most recent
    call last):, referer: http://192.168.1.1/nee.html
    [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1]
    File "/var/www/cgi-bin/noo.py", line 11, in <module>, referer:
    http://192.168.1.1/nee.html
    [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] import
    myModule,
    referer: http://192.168.1.1/nee.html
    [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] ImportError:
    No module
    named myModule, referer: http://192.168.1.1/nee.html

    =============================================
    Relevant lines from http.conf:
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    SetEnv PYTHONPATH /myModulePath
    PassEnv PYTHONPATH

    Thanks in advance for any pointers.

    bob
    bobicanprogram, Dec 12, 2008
    #1
    1. Advertising

  2. On Dec 11, 8:03 pm, bobicanprogram <> wrote:
    > Problem:
    >
    > Apache server serving an HTML file to a Firefox Browser containing a
    > form and
    > a CGI python CGI script. HTML works fine, meat of the CGI script works
    > fine
    > except that when a home grown and ordinarily functional module that is
    > to be
    > imported is added, the interpreter cannot find it.
    >
    > Running cgi.test() reveals that PYTHONPATH is correctly set. Still
    > nada.
    > Adding the sys.* stuff still nada.
    >
    > Items: Firefox Browser, Apache server, Python 2.5.
    >
    > =======================================
    >
    > The CGI script:
    > #! /usr/bin/python
    >
    > import cgi
    > #cgi.test()
    > import sys
    >
    > #sys.path.append("/myModulePath")
    > #sys.path.insert(0, "/myModulePath")
    > import myModule **************** Problem here ********************
    >
    > ===========================================
    > httpd error_log excerpt:
    > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] Traceback
    > (most recent
    > call last):, referer:http://192.168.1.1/nee.html
    > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1]
    > File "/var/www/cgi-bin/noo.py", line 11, in <module>, referer:http://192.168.1.1/nee.html
    > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] import
    > myModule,
    > referer:http://192.168.1.1/nee.html
    > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] ImportError:
    > No module
    > named myModule, referer:http://192.168.1.1/nee.html
    >
    > =============================================
    > Relevant lines from http.conf:
    > ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    > SetEnv PYTHONPATH /myModulePath
    > PassEnv PYTHONPATH
    >
    > Thanks in advance for any pointers.
    >
    > bob



    Solution found!

    The apache web server is running on a Linux box equipped with SELinux
    which
    was preventing apache from opening the required modules according to
    the
    SELinux troubleshoot browser which is available from the main menu
    under the
    administration moniker. Apache's error_log describes the problem as
    one of
    not being able to locate the said modules for import. This is
    misleading to
    say the least. Adjusting SELinux to allow this is the solution to the
    problem; this can be done under 'main menu/administration/ SELinux
    Management

    bob
    bobicanprogram, Dec 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    533
    Michael Sparks
    Jul 30, 2005
  2. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Replies:
    7
    Views:
    396
    Michael Ekstrand
    Oct 4, 2005
  3. fatted
    Replies:
    1
    Views:
    127
    Steve Grazzini
    Jul 25, 2003
  4. shumsta
    Replies:
    1
    Views:
    254
    Fabian Pilkowski
    Jul 22, 2005
  5. kath
    Replies:
    4
    Views:
    562
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page