mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Fix closes Issue #11799: urllib.request Authentication Handlers will raise a
ValueError when presented with an unsupported Authentication Scheme.
This commit is contained in:
parent
cc99528d87
commit
4de00a2e87
4 changed files with 63 additions and 16 deletions
|
@ -825,14 +825,20 @@ class AbstractBasicAuthHandler:
|
|||
self.retried += 1
|
||||
|
||||
if authreq:
|
||||
mo = AbstractBasicAuthHandler.rx.search(authreq)
|
||||
if mo:
|
||||
scheme, quote, realm = mo.groups()
|
||||
if scheme.lower() == 'basic':
|
||||
response = self.retry_http_basic_auth(host, req, realm)
|
||||
if response and response.code != 401:
|
||||
self.retried = 0
|
||||
return response
|
||||
scheme = authreq.split()[0]
|
||||
if not scheme.lower() == 'basic':
|
||||
raise ValueError("AbstractBasicAuthHandler does not"
|
||||
" support the following scheme: '%s'" %
|
||||
scheme)
|
||||
else:
|
||||
mo = AbstractBasicAuthHandler.rx.search(authreq)
|
||||
if mo:
|
||||
scheme, quote, realm = mo.groups()
|
||||
if scheme.lower() == 'basic':
|
||||
response = self.retry_http_basic_auth(host, req, realm)
|
||||
if response and response.code != 401:
|
||||
self.retried = 0
|
||||
return response
|
||||
|
||||
def retry_http_basic_auth(self, host, req, realm):
|
||||
user, pw = self.passwd.find_user_password(realm, host)
|
||||
|
@ -918,6 +924,9 @@ class AbstractDigestAuthHandler:
|
|||
scheme = authreq.split()[0]
|
||||
if scheme.lower() == 'digest':
|
||||
return self.retry_http_digest_auth(req, authreq)
|
||||
elif not scheme.lower() == 'basic':
|
||||
raise ValueError("AbstractDigestAuthHandler does not support"
|
||||
" the following scheme: '%s'" % scheme)
|
||||
|
||||
def retry_http_digest_auth(self, req, auth):
|
||||
token, challenge = auth.split(' ', 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue