Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problems with setting up mod_python and Apache

Reply
Thread Tools

Problems with setting up mod_python and Apache

 
 
John Dean
Guest
Posts: n/a
 
      09-10-2003
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
 
Reply With Quote
 
 
 
 
Dave Benjamin
Guest
Posts: n/a
 
      09-10-2003
"John Dean" <(E-Mail Removed)> wrote in message
news:3f5f6b41$0$239$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Dave Benjamin
Guest
Posts: n/a
 
      09-11-2003
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. =)


 
Reply With Quote
 
John Dean
Guest
Posts: n/a
 
      09-11-2003
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
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      09-11-2003
"John Dean" <(E-Mail Removed)> wrote in message
news:3f605bee$0$199$(E-Mail Removed)...
> 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/



 
Reply With Quote
 
John Dean
Guest
Posts: n/a
 
      09-11-2003
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
 
Reply With Quote
 
Dave Benjamin
Guest
Posts: n/a
 
      09-11-2003
"John Dean" <(E-Mail Removed)> wrote in message
news:3f605bee$0$199$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with mod_python/3.3.1 and apache NccWarp9 Python 1 03-31-2008 10:13 PM
Apache 2.2.3 and mod_python 3.2.10 m.banaouas Python 2 12-19-2006 09:56 AM
mod_python.so is garbled mod_python.so is garbled blbmdsmith Python 1 12-14-2006 12:15 AM
Help required with mod_python and apache virtual hosts andy Python 3 10-02-2004 12:02 AM
Apache mod_python and Sessions Markus Schaber Python 7 07-08-2003 05:55 PM



Advertisments