[mod_python] req.user always returns None?

Hancock, David (DHANCOCK) DHANCOCK at arinc.com
Sun Oct 19 19:57:32 EST 2003

Now that I'm using req.user instead of req.connection.user, I can get the
Tutorial's example authentication code to run without errors--thanks,
Grisha, for that.

Now, however, the example always returns HTTP_UNAUTHORIZED.  I've figured
out that this is because req.user is always None.  My browser is sending the
correct base64-encoded string for the Authorization: header. I'll append
additional information.

Thanks for any advice.

David Hancock | dhancock at arinc.com | 410-266-4384

Windows 2000
Python 2.2.3
Apache 2.0.47
mod_python 3.0.3

<Directory "C:\Program Files\Apache Group\Apache2\htdocs\authreq/"> 
  AddHandler python-program .py
  PythonHandler mptest
  PythonAuthenHandler mptest
  AuthType Basic
  AuthName "mod_python restricted area"
  require valid-user
  PythonDebug On 

from mod_python import apache

def handler(req):
    req.content_type = 'text/plain'
    req.write("Hello, world!")
    return apache.OK

def authenhandler(req):
    user = req.user
    pw = req.get_basic_auth_pw()
    req.log_error(str(user) + ' ' + str(pw))
    if user == "david" and pw == "secret":
        return apache.OK
        return apache.HTTP_UNAUTHORIZED

error_log (from req.log_error)
[Sun Oct 19 19:24:38 2003] [error] [client] None secret
[Sun Oct 19 19:25:02 2003] [error] [client] None secret

HTTP headers to and from (after initial 401)
GET /authreq/mptest.py HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b)
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Authorization: Basic ZGF2aWQ6c2VjcmV0

checking Authorization header
C:\Program Files\Apache Group\Apache2\logs>c:\python22\python
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64
>>> print base64.decodestring('ZGF2aWQ6c2VjcmV0')

More information about the Mod_python mailing list