(self, req, fp, code, msg, headers)
| 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 | |
| 92 | def _build_urllib2_request(url, agent, accept_header, etag, modified, referrer, auth, request_headers): |
nothing calls this directly
no test coverage detected