472,958 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

mod_python, multiple calls to PythonAuthenHandler


I've posted this question on the mod_python mailing list but didn't get
much response, so I thought I'd post it here.

(My first attempt connected to an unrelated thread..sorry.
Note-to-self:-must-get-more-coffee-before-posting-)

It seems to me that for each path element in a URI a mod_python handler
will be invoked. This applies to PythonAuthenHandler,
PythonHeaderParserHandler and so on.

Since I'm making a database request in my PythonAuthenHandler, this
quickly becomes a problem.

Example:
http://lucene.moonspawn.scanmine.com/ =>
AuthenHandler::authenhandler called: 1
index got called once

http://lucene.moonspawn.scanmine.com...dler.py/search =>
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
/search got called once

http://lucene.moonspawn.scanmine.com/search.html => (using mod_rewrite)
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
AuthenHandler::authenhandler called: 3
/search got called once

I get the same behavior on three separate installations

So, either I've got a miss-configuration which results in multiple calls
to handlers or.., this is expected behavior, and there is a technique to
avoid this or..., this is expected and, for reasons that escapes me,
desired behavior.

I'd greatly appreciate any help and suggestion

regards

/rune
Jul 18 '05 #1
3 2140
Rune Hansen wrote:
I've posted this question on the mod_python mailing list but didn't get
much response, so I thought I'd post it here.

(My first attempt connected to an unrelated thread..sorry.
Note-to-self:-must-get-more-coffee-before-posting-)

It seems to me that for each path element in a URI a mod_python handler
will be invoked. This applies to PythonAuthenHandler,
PythonHeaderParserHandler and so on.

Since I'm making a database request in my PythonAuthenHandler, this
quickly becomes a problem.

Example:
http://lucene.moonspawn.scanmine.com/ =>
AuthenHandler::authenhandler called: 1
index got called once

http://lucene.moonspawn.scanmine.com...dler.py/search =>
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
/search got called once

http://lucene.moonspawn.scanmine.com/search.html => (using mod_rewrite)
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
AuthenHandler::authenhandler called: 3
/search got called once

I get the same behavior on three separate installations

So, either I've got a miss-configuration which results in multiple calls
to handlers or.., this is expected behavior, and there is a technique to
avoid this or..., this is expected and, for reasons that escapes me,
desired behavior.

I'd greatly appreciate any help and suggestion

regards

/rune


Well, the thing that's missing here is the code of your AuthenHandler
(or some detail about which standard component you think is being used).
Is it possible you are making internal redirects, for example?

The information about using mod_rewrite does imply you are spending time
on authentication rather more frequently than you strictly need to, but
it's difficult to figure out from just the information given.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #2
On Mon, 08 Nov 2004 08:18:45 -0500, Steve Holden wrote:
Rune Hansen wrote:
I've posted this question on the mod_python mailing list but didn't get
much response, so I thought I'd post it here.

(My first attempt connected to an unrelated thread..sorry.
Note-to-self:-must-get-more-coffee-before-posting-)

It seems to me that for each path element in a URI a mod_python handler
will be invoked. This applies to PythonAuthenHandler,
PythonHeaderParserHandler and so on.

Since I'm making a database request in my PythonAuthenHandler, this
quickly becomes a problem.

Example:
http://lucene.moonspawn.scanmine.com/ =>
AuthenHandler::authenhandler called: 1
index got called once

http://lucene.moonspawn.scanmine.com...dler.py/search =>
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
/search got called once

http://lucene.moonspawn.scanmine.com/search.html => (using mod_rewrite)
AuthenHandler::authenhandler called: 1
AuthenHandler::authenhandler called: 2
AuthenHandler::authenhandler called: 3
/search got called once

I get the same behavior on three separate installations

So, either I've got a miss-configuration which results in multiple calls
to handlers or.., this is expected behavior, and there is a technique to
avoid this or..., this is expected and, for reasons that escapes me,
desired behavior.

I'd greatly appreciate any help and suggestion

regards

/rune


Well, the thing that's missing here is the code of your AuthenHandler
(or some detail about which standard component you think is being used).
Is it possible you are making internal redirects, for example?

The information about using mod_rewrite does imply you are spending time
on authentication rather more frequently than you strictly need to, but
it's difficult to figure out from just the information given.

regards
Steve


Hi Steve,
The configuration and "files" shown below results in the "Example" of my
orignal post.

httpd.conf:
"""
<VirtualHost *:80>
ServerName lucene.moonspawn.scanmine.com
ServerAdmin ru*********@scanmine.com
DocumentRoot /Users/roderik/Sites/Lucene
ErrorLog logs/lucene_error.log
CustomLog logs/lucene_access.log common
</VirtualHost>
<Directory "/Users/roderik/Sites/Lucene">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
RewriteEngine On
RewriteBase /
RewriteRule search.html "SearchHandler.py/search"
AddHandler mod_python .py
DirectoryIndex SearchHandler.py
PythonHandler mod_python.publisher
PythonAuthenHandler AuthenHandler
AuthType Basic
AuthName "Restricted Area"
require valid-user
PythonPath "sys.path+['/Users/roderik/Sites/Lucene']"
PythonDebug On
</Directory>
"""

AuthenHandler.py
"""
from mod_python import apache

count=0

def authenhandler(req,**args):
global count

count +=1
req.write("AuthenHandler::authenhandler called: "+str(count)+"\n")

pw = req.get_basic_auth_pw()
user = req.user

if user == "mrX" and pw == "1234":
return apache.OK
else:
return apache.HTTP_UNAUTHORIZED
"""

SearchHandler.py
"""
from mod_python import apache

def index(req,**args):
req.content_type = "text/html"
req.write("<html><head><title>Search Index Page</title><head><body>## 'index' got called once</body></html>")

def search(req,**args):
req.content_type = "text/html"
req.write("<html><head><title>Search /search Page</title><head><body>## '/search' got called once</body></html>")
"""

Now, I've "solved it" with a single PythonHandler (dropping
PythonAuthenHandler and publisher):

def handler(req):
if not req.headers_in.get("Authorization",0):
req.err_headers_out["WWW-Authenticate"] = 'Basic realm="Restricted\
area"'
raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED
meth,auth = req.headers_in.get("Authorization").split(" ")
user,pw = decodestring(auth).split(":")
args = dict([(a[0],a[1]) for a in util.parse_qsl(req.args or '')])
if dbmdbValidate(user,pw,req.server):
return myMethod(req,**args)
else:
return apache.HTTP_UNAUTHORIZED

This seems to do exactly what I want. Guess I should have tried a litle
harder before posting.
How ever, I'm still curious to why the PythonAuthenHandler is called for
each path element.

regards
/rune
Jul 18 '05 #3
Rune Hansen wrote:
On Mon, 08 Nov 2004 08:18:45 -0500, Steve Holden wrote:

Rune Hansen wrote:

I've posted this question on the mod_python mailing list but didn't get
much response, so I thought I'd post it here.
[...]
Now, I've "solved it" with a single PythonHandler (dropping
PythonAuthenHandler and publisher):

def handler(req):
if not req.headers_in.get("Authorization",0):
req.err_headers_out["WWW-Authenticate"] = 'Basic realm="Restricted\
area"'
raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED
meth,auth = req.headers_in.get("Authorization").split(" ")
user,pw = decodestring(auth).split(":")
args = dict([(a[0],a[1]) for a in util.parse_qsl(req.args or '')])
if dbmdbValidate(user,pw,req.server):
return myMethod(req,**args)
else:
return apache.HTTP_UNAUTHORIZED

This seems to do exactly what I want. Guess I should have tried a litle
harder before posting.
How ever, I'm still curious to why the PythonAuthenHandler is called for
each path element.


I'm afraid that's a little beyond me too, but I think you were quite
within your rights to post the question. Glad you've got past the problem.

Since you're using the publisher handler you might want to consider
using the methods described in
http://www.modpython.org/live/curren...-alg-auth.html if
you haven't already looked at them.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ravi | last post by:
Hi, I am considering embarking on a project with mod_python. However I am wondering if the mod_python interpreter is embedded or actually calls the python executable. The documentation says the...
1
by: Nancy | last post by:
Hi, I follow the Mod_python manual and try to let my form.py to handle html form. The form.html and form.py are copied from http://www.modpython.org/live/current/doc-html/tut-pub.html, after I...
5
by: Peter Clark | last post by:
Think of something like MyYahoo: a personalized portal with news aggregator, weather forecast, comics, etc. Now instead of visiting a web site, think of all of it being sent daily as an email. It...
6
by: Anthony L. | last post by:
I am writing a web application that is comparable to a content management system used in blogging. I really want to use Python after having done some evaluation coding using Python 2.3.5 with...
3
by: mneagul | last post by:
Hello! I am writing a small program using mod_python publisher extension. I have created several python files and imported them in a `main' file. How can I stop mod_python to byte compile the...
1
by: boney | last post by:
hello All, I am totally unknown to python language.. i need to install mod_python to embed python interpreter with the Apache server, in order to use Trac with Apache Web Server i am using...
5
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major...
1
by: blbmdsmith | last post by:
Has anyone seen the following error while starting httpd: Starting httpd: httpd: Syntax error on line 54 of /usr/local/apache2/conf/httpd.conf: API module structure `python_module' in file...
3
by: Lawrence D'Oliveiro | last post by:
In message <mailman.109.1216158151.922.python-list@python.org>, Cyril Bazin wrote: What's the error message? This should be in Apache's error_log file.
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.