Problems with setting up mod_python and Apache

Discussion in 'Python' started by John Dean, Sep 10, 2003.

  1. John Dean

    John Dean Guest

    Hi
    I have set up httpd.conf according to installation and configuration
    instructions in the mod_python documentation. Yet when I enter the following
    URL http://localhost/test.py all I get is an Apache view of my htdocs
    directory. They if I click on test.py and open file dialog pops up. If I
    give the file a cgi extension and enter the following URL
    http://locathost/test.cgi it runs fine. I just can't figure out what I am
    doing wrong.

    --
    Best Regards
    John
     
    John Dean, Sep 10, 2003
    #1
    1. Advertising

  2. "John Dean" <> wrote in message
    news:3f5f6b41$0$239$...
    > I have set up httpd.conf according to installation and configuration
    > instructions in the mod_python documentation. Yet when I enter the

    following
    > URL http://localhost/test.py all I get is an Apache view of my htdocs
    > directory. They if I click on test.py and open file dialog pops up. If I
    > give the file a cgi extension and enter the following URL
    > http://locathost/test.cgi it runs fine. I just can't figure out what I am
    > doing wrong.


    Sounds like a configuration problem. Can you post the relevant lines from
    your httpd.conf file? Are you trying to write handlers or are you using the
    publisher module?

    Dave
     
    Dave Benjamin, Sep 10, 2003
    #2
    1. Advertising

  3. Quoting John Dean:
    >
    > Here are the lines in my httpd.conf
    > LoadModule python_module /usr/lib/apache/mod_python.so
    >
    > AddModule mod_python.c
    >
    > <Directory "srv/www/htdocs">
    > .....
    > .....
    >
    > Addhandler python-program .py
    > PythonHandler test


    Looks right to me. Have you verified that:
    a) you are editing the right httpd.conf (hey, it happens...)
    b) you are affecting the directory you think you are (do other apache
    directives work properly?)

    Once things are working, you may also want to read up on and consider adding
    this:
    PythonInterpPerDirectory on
    (hint: otherwise, if you have a test.py in another directory, you will get
    bizarre results)

    Good luck,
    Dave

    PS - Please keep replies to the list for the benefit of others. =)
     
    Dave Benjamin, Sep 11, 2003
    #3
  4. John Dean

    John Dean Guest

    Hi Dave

    I have fixed my problem with mod_python. I have one small problem left to
    sort out. If I enter the URL http://localhost Apache just displays the
    contents of the htdocs directory, but if I enter the URL
    http://localhost/test.py everything works as it should. I guess this is
    somewhat off topic since it appears to be an Apache configuration problem so
    I hope you don't mind me asking you for your opinion on c.l.p.

    BTW What I am trying to do is to move away from PHP. Since I use Python as
    my primary scripting language for just about everything where you would use
    a scripting language, it seems to me to be a reasonable idea to use Python
    to provide dyanamic content for the web sites I look after.

    --
    Best Regards
    John
     
    John Dean, Sep 11, 2003
    #4
  5. John Dean

    Steve Holden Guest

    "John Dean" <> wrote in message
    news:3f605bee$0$199$...
    > Hi Dave
    >
    > I have fixed my problem with mod_python. I have one small problem left to
    > sort out. If I enter the URL http://localhost Apache just displays the
    > contents of the htdocs directory, but if I enter the URL
    > http://localhost/test.py everything works as it should. I guess this is
    > somewhat off topic since it appears to be an Apache configuration problem

    so
    > I hope you don't mind me asking you for your opinion on c.l.p.
    >

    Yes, you should condition your server not to give you a directory listing
    when the default documents aren't found - this is big-time information
    leakage, and gives an attacker leverage to start finding vulnerabilities.
    So, beofre you go into production, fix that! The config command you need is
    something like

    DirectoryIndex index.htm index.html index.html.var index.php

    You might want to include index.py there too!

    How did you solve your mod_python problem, by the way?

    > BTW What I am trying to do is to move away from PHP. Since I use Python as
    > my primary scripting language for just about everything where you would

    use
    > a scripting language, it seems to me to be a reasonable idea to use Python
    > to provide dyanamic content for the web sites I look after.
    >

    Nice. Just try to resist the temptation to replace working PHP with working
    Python - nobody's paying you for that! Translate to Python when upgrading,
    or for new functionality.

    still-from-Yorkshire-ly y'rs - steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/pwp/
     
    Steve Holden, Sep 11, 2003
    #5
  6. John Dean

    John Dean Guest

    Hi Steve
    Thank you very much for your reply
    Funnily enough I sorted out Apache problem before reading you post. Thanks
    all the same.
    I have mod_python working like a dream. So now in to the hard part. I hope
    you won't mind if I explain. The project I am working on, Rekall, contains
    serveral WSYWIG designers. Two of these designers are of particular interest
    for what I have in mind - the Form and Report Designers. Form and Report
    definitions are stored in XML format either as a file in the file system or
    in a SQL Database. The basic idea is to load a string object with the form
    or report definition. Then using Pythons XML DOM module build a HTML
    document plus the required SQL query string(s). If it is a form then we'll
    will need to build both the HTML data input form and the backend form
    processor. I guess this will need a publisher handler. I expect Reports to
    be a lot easier, but since I am talking about several report output during a
    single session I suppose I will need to get my head around dynamic handlers.
    Now that's frightening

    --
    Best Regards
    John
     
    John Dean, Sep 11, 2003
    #6
  7. "John Dean" <> wrote in message
    news:3f605bee$0$199$...
    > I have fixed my problem with mod_python. I have one small problem left to
    > sort out. If I enter the URL http://localhost Apache just displays the
    > contents of the htdocs directory, but if I enter the URL
    > http://localhost/test.py everything works as it should. I guess this is
    > somewhat off topic since it appears to be an Apache configuration problem

    so
    > I hope you don't mind me asking you for your opinion on c.l.p.


    Well, I get around this problem by adding "index.py" to the DirectoryIndex
    directive. I use a modified version of the publisher module that comes with
    mod_python that handles this and related special cases. Here's the change
    that I make, if you're interested:

    < if not _req.subprocess_env.has_key("PATH_INFO"):
    < raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
    <
    < func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
    < func_path = string.replace(func_path, "/", ".")
    ---
    > if _req.subprocess_env.has_key("PATH_INFO"):
    > func_path = _req.subprocess_env["PATH_INFO"][1:] # skip first /
    > func_path = string.replace(func_path, "/", ".")
    >
    > # If no function is specified, assume "default".
    > if not len(func_path): func_path = "default"
    > else:
    > # If no module is specified either, assume "index".
    > func_path = "default"
    > module_name = "index"


    This has the result that "index" is always the default module, and "default"
    is the function within that module that gets called if no function is
    explicitly specified on the URL. This works like a charm.

    > BTW What I am trying to do is to move away from PHP. Since I use Python as
    > my primary scripting language for just about everything where you would

    use
    > a scripting language, it seems to me to be a reasonable idea to use Python
    > to provide dyanamic content for the web sites I look after.


    I did the same thing myself last year, after writing PHP for a couple of
    years. mod_python definitely makes Python a worthy substitute for writing
    Apache modules. The main drawbacks from my experience are the lack of
    built-in session handling and more sophisticated parameter passing (ie.
    PHP's ability to serialize hashes from a form submission). But I'm a little
    dated now, I'm still using mod_python 2 / apache 1.3 ...

    Have fun,
    Dave
     
    Dave Benjamin, Sep 11, 2003
    #7
    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. Markus Schaber

    Apache mod_python and Sessions

    Markus Schaber, Jul 4, 2003, in forum: Python
    Replies:
    7
    Views:
    855
    Irmen de Jong
    Jul 8, 2003
  2. andy
    Replies:
    3
    Views:
    408
    Michael Fuhr
    Oct 2, 2004
  3. blbmdsmith
    Replies:
    1
    Views:
    654
    Graham Dumpleton
    Dec 14, 2006
  4. m.banaouas

    Apache 2.2.3 and mod_python 3.2.10

    m.banaouas, Dec 19, 2006, in forum: Python
    Replies:
    2
    Views:
    652
    Graham Dumpleton
    Dec 19, 2006
  5. NccWarp9
    Replies:
    1
    Views:
    437
    Graham Dumpleton
    Mar 31, 2008
Loading...

Share This Page