472,146 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

mod_python apache configuration issues

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
Jul 18 '05 #1
2 2771
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
Jul 18 '05 #2
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rolfe | last post: by
1 post views Thread by wolf | last post: by
3 posts views Thread by Rune Hansen | last post: by
1 post views Thread by treelife | last post: by
9 posts views Thread by cyberco | last post: by
10 posts views Thread by walterbyrd | last post: by
10 posts views Thread by Vincent Delporte | last post: by
5 posts views Thread by m.banaouas | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.