Index: Lib/urllib2.py =================================================================== --- Lib/urllib2.py (revision 88915) +++ Lib/urllib2.py (working copy) @@ -803,12 +803,11 @@ class AbstractBasicAuthHandler: # XXX this allows for multiple auth-schemes, but will stupidly pick - # the last one with a realm specified. + # the first one with basic auth and a realm specified. # allow for double- and single-quoted realm values # (single quotes are a violation of the RFC, but appear in the wild) - rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+' - 'realm=(["\'])(.*?)\\2', re.I) + rx = re.compile(r'basic[ \t]+realm=(["\'])(.*?)\1', re.I) # XXX could pre-emptively send auth info already accepted (RFC 2617, # end of section 2, and section 1.2 immediately after "credentials" @@ -837,9 +836,8 @@ if authreq: mo = AbstractBasicAuthHandler.rx.search(authreq) if mo: - scheme, quote, realm = mo.groups() - if scheme.lower() == 'basic': - return self.retry_http_basic_auth(host, req, realm) + quote, realm = mo.groups() + return self.retry_http_basic_auth(host, req, realm) def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host)