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. Cheers! -- David Hancock | dhancock at arinc.com | 410-266-4384 system ====== Windows 2000 Python 2.2.3 Apache 2.0.47 mod_python 3.0.3 httpd.conf ========== <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 </Directory> mptest.py ========= from mod_python import apache def handler(req): req.content_type = 'text/plain' req.send_http_header() 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 else: return apache.HTTP_UNAUTHORIZED error_log (from req.log_error) ============================== [Sun Oct 19 19:24:38 2003] [error] [client 127.0.0.1] None secret [Sun Oct 19 19:25:02 2003] [error] [client 127.0.0.1] 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) Gecko/20030827 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q= 0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1 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') david:secret >>>
|