Fixing bug #227562 by calling URLopener.http_error_default when

an invalid 401 request is being handled.
This commit is contained in:
Moshe Zadka 2001-02-27 06:27:04 +00:00
parent be77cf7d57
commit e99bd17ed6

View file

@ -560,18 +560,24 @@ class FancyURLopener(URLopener):
"""Error 401 -- authentication required. """Error 401 -- authentication required.
See this URL for a description of the basic authentication scheme: See this URL for a description of the basic authentication scheme:
http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt""" http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt"""
if headers.has_key('www-authenticate'): if not headers.has_key('www-authenticate'):
stuff = headers['www-authenticate'] URLopener.http_error_default(self, url, fp,
import re errmsg, headers)
match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff) stuff = headers['www-authenticate']
if match: import re
scheme, realm = match.groups() match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
if scheme.lower() == 'basic': if not match:
name = 'retry_' + self.type + '_basic_auth' URLopener.http_error_default(self, url, fp,
if data is None: errcode, errmsg, headers)
return getattr(self,name)(url, realm) scheme, realm = match.groups()
else: if scheme.lower() != 'basic':
return getattr(self,name)(url, realm, data) URLopener.http_error_default(self, url, fp,
errcode, errmsg, headers)
name = 'retry_' + self.type + '_basic_auth'
if data is None:
return getattr(self,name)(url, realm)
else:
return getattr(self,name)(url, realm, data)
def retry_http_basic_auth(self, url, realm, data=None): def retry_http_basic_auth(self, url, realm, data=None):
host, selector = splithost(url) host, selector = splithost(url)