diff -r 5973743a52a1 Lib/urllib/request.py --- a/Lib/urllib/request.py Sun Mar 06 18:10:58 2011 -0600 +++ b/Lib/urllib/request.py Fri Apr 08 00:53:42 2011 +0300 @@ -811,14 +811,18 @@ self.retried += 1 if authreq: - mo = AbstractBasicAuthHandler.rx.search(authreq) - if mo: - scheme, quote, realm = mo.groups() - if scheme.lower() == 'basic': + scheme = authreq.split()[0] + if scheme.lower() == 'basic': + mo = AbstractBasicAuthHandler.rx.search(authreq) + if mo: + scheme, quote, realm = mo.groups() response = self.retry_http_basic_auth(host, req, realm) if response and response.code != 401: self.retried = 0 return response + else: + raise HTTPError(req.full_url, 401, "not basic auth: '%s'" % scheme, + headers, None) def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) @@ -904,6 +908,10 @@ scheme = authreq.split()[0] if scheme.lower() == 'digest': return self.retry_http_digest_auth(req, authreq) + else: + raise HTTPError(req.full_url, 401, "not digest auth: '%s'" % scheme, + headers, None) + def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1)