mod_python apache configuration issues

Discussion in 'Python' started by digidalmation, Oct 18, 2004.

  1. Hello all. I've been trying to get my linux server to run mod_python.
    It's a Mandrake 10 linux box, and apache/mod_python are installed from rpms.
    apache2-mod_python-2.0.48_3.1.3-1mdk
    apache2-2.0.48-6mdk


    The rpm installed the python module as:
    /usr/lib/apache2-extramodules/mod_python.so

    And added a config file for apache:
    /etc/httpd/conf.d/16_mod_python.conf

    The apache config files contained the following before my modifications:
    <IfDefine HAVE_PYTHON>
    <IfModule !mod_python.c>
    LoadModule python_module extramodules/mod_python.so
    </IfModule>
    </IfDefine>
    <IfModule mod_python.c>
    </IfModule>

    Now after reading the docs installed into /usr/share/doc for mod_python
    and going through the directions at python.org, I've also changed the
    config file to add a few lines to one of the directives:

    <Directory /var/www/html>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On
    </Directory>

    Now when I put the url into a browser:
    http://myserver.mydomain.com/mptest.py

    I get a popup from the browser because it doesn't know how to handle
    mptest.py, and it asks what you want to do with the file (open it with
    an application, save it to disk, etc). I can choose to open the file
    with a text editor, and all it shows is the text "hello world".

    That's the output of the mptest.py script.... apache isn't feeding the
    browser the code from the mptest.py, only the output. (Otherwise when I
    open it in a text editor I'd see the entire mptest.py script.

    Contents of the mptest.py script:
    from mod_python import apache

    def handler(req):
    req.write("Hello World!")
    return apache.OK

    I'm not a python developer, but have been working with Linux and Apache
    for a number of years. I'm not sure where to go from here. It appears
    that the script gets compiled - there is a mptest.pyc file in the
    directory now. Why is it sending my browser the mptest.py file with the
    stdout of the script?

    Thanks in advance. Any help on this is appreciated.

    Dave
     
    digidalmation, Oct 18, 2004
    #1
    1. Advertising

  2. digidalmation

    David Fraser Guest

    digidalmation wrote:
    > Hello all. I've been trying to get my linux server to run mod_python.
    > It's a Mandrake 10 linux box, and apache/mod_python are installed from
    > rpms.
    > apache2-mod_python-2.0.48_3.1.3-1mdk
    > apache2-2.0.48-6mdk
    >
    >
    > The rpm installed the python module as:
    > /usr/lib/apache2-extramodules/mod_python.so
    >
    > And added a config file for apache:
    > /etc/httpd/conf.d/16_mod_python.conf
    >
    > The apache config files contained the following before my modifications:
    > <IfDefine HAVE_PYTHON>
    > <IfModule !mod_python.c>
    > LoadModule python_module extramodules/mod_python.so
    > </IfModule>
    > </IfDefine>
    > <IfModule mod_python.c>
    > </IfModule>
    >
    > Now after reading the docs installed into /usr/share/doc for mod_python
    > and going through the directions at python.org, I've also changed the
    > config file to add a few lines to one of the directives:
    >
    > <Directory /var/www/html>
    > Options -Indexes FollowSymLinks MultiViews
    > AllowOverride All
    > AddHandler mod_python .py
    > PythonHandler mptest
    > PythonDebug On
    > </Directory>
    >
    > Now when I put the url into a browser:
    > http://myserver.mydomain.com/mptest.py
    >
    > I get a popup from the browser because it doesn't know how to handle
    > mptest.py, and it asks what you want to do with the file (open it with
    > an application, save it to disk, etc). I can choose to open the file
    > with a text editor, and all it shows is the text "hello world".
    >
    > That's the output of the mptest.py script.... apache isn't feeding the
    > browser the code from the mptest.py, only the output. (Otherwise when I
    > open it in a text editor I'd see the entire mptest.py script.
    >
    > Contents of the mptest.py script:
    > from mod_python import apache
    >
    > def handler(req):
    > req.write("Hello World!")
    > return apache.OK
    >
    > I'm not a python developer, but have been working with Linux and Apache
    > for a number of years. I'm not sure where to go from here. It appears
    > that the script gets compiled - there is a mptest.pyc file in the
    > directory now. Why is it sending my browser the mptest.py file with the
    > stdout of the script?
    >
    > Thanks in advance. Any help on this is appreciated.
    >
    > Dave
    >
    >


    This is working properly, all you want to do is set the content type so
    that your browser can understand it:
    req.content_type = "text/plain"
    or something like that should do it.

    David
     
    David Fraser, Oct 19, 2004
    #2
    1. Advertising

  3. David Fraser wrote:
    > digidalmation wrote:
    >
    >> Hello all. I've been trying to get my linux server to run mod_python.
    >> It's a Mandrake 10 linux box, and apache/mod_python are installed from
    >> rpms.
    >> apache2-mod_python-2.0.48_3.1.3-1mdk
    >> apache2-2.0.48-6mdk
    >>
    >>
    >> The rpm installed the python module as:
    >> /usr/lib/apache2-extramodules/mod_python.so
    >>
    >> And added a config file for apache:
    >> /etc/httpd/conf.d/16_mod_python.conf
    >>
    >> The apache config files contained the following before my modifications:
    >> <IfDefine HAVE_PYTHON>
    >> <IfModule !mod_python.c>
    >> LoadModule python_module extramodules/mod_python.so
    >> </IfModule>
    >> </IfDefine>
    >> <IfModule mod_python.c>
    >> </IfModule>
    >>
    >> Now after reading the docs installed into /usr/share/doc for mod_python
    >> and going through the directions at python.org, I've also changed the
    >> config file to add a few lines to one of the directives:
    >>
    >> <Directory /var/www/html>
    >> Options -Indexes FollowSymLinks MultiViews
    >> AllowOverride All
    >> AddHandler mod_python .py
    >> PythonHandler mptest
    >> PythonDebug On
    >> </Directory>
    >>
    >> Now when I put the url into a browser:
    >> http://myserver.mydomain.com/mptest.py
    >>
    >> I get a popup from the browser because it doesn't know how to handle
    >> mptest.py, and it asks what you want to do with the file (open it with
    >> an application, save it to disk, etc). I can choose to open the file
    >> with a text editor, and all it shows is the text "hello world".
    >>
    >> That's the output of the mptest.py script.... apache isn't feeding the
    >> browser the code from the mptest.py, only the output. (Otherwise when I
    >> open it in a text editor I'd see the entire mptest.py script.
    >>
    >> Contents of the mptest.py script:
    >> from mod_python import apache
    >>
    >> def handler(req):
    >> req.write("Hello World!")
    >> return apache.OK
    >>
    >> I'm not a python developer, but have been working with Linux and Apache
    >> for a number of years. I'm not sure where to go from here. It appears
    >> that the script gets compiled - there is a mptest.pyc file in the
    >> directory now. Why is it sending my browser the mptest.py file with the
    >> stdout of the script?
    >>
    >> Thanks in advance. Any help on this is appreciated.
    >>
    >> Dave
    >>
    >>

    >
    > This is working properly, all you want to do is set the content type so
    > that your browser can understand it:
    > req.content_type = "text/plain"
    > or something like that should do it.
    >
    > David


    David, you steered me in the right direction! I just added this to my
    apache config file, and voila... it works.

    AddType text/plain .py

    Many thanks David.

    Dave
     
    digidalmation, Oct 21, 2004
    #3
    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:
    879
    Irmen de Jong
    Jul 8, 2003
  2. Bowen Chiu
    Replies:
    1
    Views:
    568
    Skip Montanaro
    Aug 9, 2003
  3. John Dean
    Replies:
    6
    Views:
    471
    Dave Benjamin
    Sep 11, 2003
  4. blbmdsmith
    Replies:
    1
    Views:
    681
    Graham Dumpleton
    Dec 14, 2006
  5. Danilo
    Replies:
    5
    Views:
    358
    Graham Dumpleton
    Mar 9, 2007
Loading...

Share This Page