Problem with RE in AbstractBasicAuthHandler

Catalin Marinas c_marinas at
Tue Jul 20 17:36:07 CEST 2004


I was trying to use the HTTPBasicAuthHandler with an MS web server
requiring authentication (basic) but without success. I digged a bit
in the urllib2 module (python 2.3.4) and it turned out to be a problem
with the regular expression matching in the
AbstractBasicAuthHandler.http_error_auth_reqed() function. The
rx.match() cannot be used since it always matches from the beginning
of the string and the reply from my server had 2 more words in front
(Negotiate, NTLM, Basic realm="...").

The patch below fixes this by replacing match() with search():

---	2004-07-20 16:10:28.000000000 +0100
+++	2004-07-20 16:29:34.000000000 +0100
@@ -631,7 +631,7 @@
         # XXX could be multiple headers
         authreq = headers.get(authreq, None)
         if authreq:
-            mo = AbstractBasicAuthHandler.rx.match(authreq)
+            mo =
             if mo:
                 scheme, realm = mo.groups()
                 if scheme.lower() == 'basic':



More information about the Python-list mailing list