MCPcopy Create free account
hub / github.com/kurtmckee/feedparser / http_error_401

Method http_error_401

feedparser/http.py:70–89  ·  view source on GitHub ↗
(self, req, fp, code, msg, headers)

Source from the content-addressed store, hash-verified

68 http_error_307 = http_error_301
69
70 def http_error_401(self, req, fp, code, msg, headers):
71 # Check if
72 # - server requires digest auth, AND
73 # - we tried (unsuccessfully) with basic auth, AND
74 # If all conditions hold, parse authentication information
75 # out of the Authorization header we sent the first time
76 # (for the username and password) and the WWW-Authenticate
77 # header the server sent back (for the realm) and retry
78 # the request with the appropriate digest auth headers instead.
79 # This evil genius hack has been brought to you by Aaron Swartz.
80 host = urllib.parse.urlparse(req.get_full_url())[1]
81 if 'Authorization' not in req.headers or 'WWW-Authenticate' not in headers:
82 return self.http_error_default(req, fp, code, msg, headers)
83 auth = base64.decodebytes(req.headers['Authorization'].split(' ')[1].encode()).decode()
84 user, passw = auth.split(':')
85 realm = re.findall('realm="([^"]*)"', headers['WWW-Authenticate'])[0]
86 self.add_password(realm, host, user, passw)
87 retry = self.http_error_auth_reqed('www-authenticate', host, req, headers)
88 self.reset_retry_count()
89 return retry
90
91
92def _build_urllib2_request(url, agent, accept_header, etag, modified, referrer, auth, request_headers):

Callers

nothing calls this directly

Calls 1

http_error_defaultMethod · 0.95

Tested by

no test coverage detected