[mod_python] mod_python tutorial issues

Joshua Gramlich jgramlich at piocon.com
Tue Nov 12 10:21:32 EST 2002


Okay, my environment:

redhat linux 7.2
mod_python == most recent beta 4 of version 3 (compiled as dso)
apache == 2.0.43
python == 2.2.1 threads enabled...

Now, I'm going through the tutorial, and the little "hello world" program
seems to work just fine.  It's when I get to the authentication piece that
it messes up.  Here's the file I'm trying to "run":

################## myscript.py ##################################
from mod_python import apache

def authenhandler(req):
    pw = req.get_basic_auth_pw()
    user = req.connection.user
    if user == "spam" and pw == "eggs":
        return apache.OK
    else:
        return apache.HTTP_UNAUTHORIZED

def handler(pik):
    pik.content_type = "text/plain"
    pik.send_http_header()
    pik.write("Hello cruel World!")
    pik.write("Eat my shirt...")
    return apache.OK

#######################################################

...and the following is the error_log entry of apache when running:



[Tue Nov 12 10:03:51 2002] [notice] Graceful restart requested, doing
restart
[Tue Nov 12 10:03:57 2002] [notice] Apache/2.0.43 (Unix)
mod_python/3.0-BETA4 Python/2.2.1 configured -- resuming normal operations
[Tue Nov 12 10:05:12 2002] [error] [client 65.195.58.203]
PythonAuthenHandler myscript: Traceback (most recent call last):
[Tue Nov 12 10:05:12 2002] [error] [client 65.195.58.203]
PythonAuthenHandler myscript:   File
"/usr/lib/python2.2/site-packages/mod_python/apache.py", line 335, in
HandlerDispatch
    result = object(req)
[Tue Nov 12 10:05:12 2002] [error] [client 65.195.58.203]
PythonAuthenHandler myscript:   File
"/var/www/webroot/modpythontest/myscript.py", line 7, in authenhandler
    user = req.connection.user
[Tue Nov 12 10:05:12 2002] [error] [client 65.195.58.203]
PythonAuthenHandler myscript: AttributeError: user


Other behavior:
...when trying to access the "myscript.py" file, the internet explorer
authentication popup box appears...asking for username and password.
Whatever you enter for username and password does not matter, and every time
you hit the "OK" button, I get the Internal Server Error (see above) page
from IE.  If I hit "Cancel" instead, I get the "You must be authorized
blahblahblah...", so it looks as though the Apache portion is working...


Josh
Chicago, IL




More information about the Mod_python mailing list