473,324 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 2161
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.