Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e99bd17

Browse files
author
Moshe Zadka
committed
Fixing bug #227562 by calling URLopener.http_error_default when
an invalid 401 request is being handled.
1 parent be77cf7 commit e99bd17

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

Lib/urllib.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,24 @@ def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
560560
"""Error 401 -- authentication required.
561561
See this URL for a description of the basic authentication scheme:
562562
http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt"""
563-
if headers.has_key('www-authenticate'):
564-
stuff = headers['www-authenticate']
565-
import re
566-
match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
567-
if match:
568-
scheme, realm = match.groups()
569-
if scheme.lower() == 'basic':
570-
name = 'retry_' + self.type + '_basic_auth'
571-
if data is None:
572-
return getattr(self,name)(url, realm)
573-
else:
574-
return getattr(self,name)(url, realm, data)
563+
if not headers.has_key('www-authenticate'):
564+
URLopener.http_error_default(self, url, fp,
565+
errmsg, headers)
566+
stuff = headers['www-authenticate']
567+
import re
568+
match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
569+
if not match:
570+
URLopener.http_error_default(self, url, fp,
571+
errcode, errmsg, headers)
572+
scheme, realm = match.groups()
573+
if scheme.lower() != 'basic':
574+
URLopener.http_error_default(self, url, fp,
575+
errcode, errmsg, headers)
576+
name = 'retry_' + self.type + '_basic_auth'
577+
if data is None:
578+
return getattr(self,name)(url, realm)
579+
else:
580+
return getattr(self,name)(url, realm, data)
575581

576582
def retry_http_basic_auth(self, url, realm, data=None):
577583
host, selector = splithost(url)

0 commit comments

Comments
 (0)