Python urllib.request.add_unredirected_header() Examples
The following are 30
code examples of urllib.request.add_unredirected_header().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urllib.request
, or try the search function
.
Example #1
Source File: request.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #2
Source File: request.py From arissploit with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #3
Source File: request.py From gimp-plugin-export-layers with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #4
Source File: check_docker.py From check_docker with GNU General Public License v3.0 | 5 votes |
def process_oauth2(self, request, response, www_authenticate_header): # This keeps infinite auth loops from happening full_url = request.full_url self.auth_failure_tracker[full_url] += 1 if self.auth_failure_tracker[full_url] > 1: raise HTTPError(full_url, 401, "Stopping Oauth2 failure loop for {}".format(full_url), response.headers, response) auth_token = self._get_outh2_token(www_authenticate_header) request.add_unredirected_header('Authorization', 'Bearer ' + auth_token) return self.parent.open(request, timeout=request.timeout)
Example #5
Source File: request.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #6
Source File: request.py From gimp-plugin-export-layers with GNU General Public License v3.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #7
Source File: request.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #8
Source File: request.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #9
Source File: request.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #10
Source File: request.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #11
Source File: request.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #12
Source File: request.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #13
Source File: cookiejar.py From android_universal with MIT License | 5 votes |
def add_cookie_header(self, request): """Add correct Cookie: header to request (urllib.request.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true. """ _debug("add_cookie_header") self._cookies_lock.acquire() try: self._policy._now = self._now = int(time.time()) cookies = self._cookies_for_request(request) attrs = self._cookie_attrs(cookies) if attrs: if not request.has_header("Cookie"): request.add_unredirected_header( "Cookie", "; ".join(attrs)) # if necessary, advertise that we know RFC 2965 if (self._policy.rfc2965 and not self._policy.hide_cookie2 and not request.has_header("Cookie2")): for cookie in cookies: if cookie.version != 1: request.add_unredirected_header("Cookie2", '$Version="1"') break finally: self._cookies_lock.release() self.clear_expired_cookies()
Example #14
Source File: request.py From arissploit with GNU General Public License v3.0 | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #15
Source File: request.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.get_header(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #16
Source File: request.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def http_request(self, req): if (not hasattr(self.passwd, 'is_authenticated') or not self.passwd.is_authenticated(req.full_url)): return req if not req.has_header('Authorization'): user, passwd = self.passwd.find_user_password(None, req.full_url) credentials = '{0}:{1}'.format(user, passwd).encode() auth_str = base64.standard_b64encode(credentials).decode() req.add_unredirected_header('Authorization', 'Basic {}'.format(auth_str.strip())) return req
Example #17
Source File: cookiejar.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def add_cookie_header(self, request): """Add correct Cookie: header to request (urllib.request.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true. """ _debug("add_cookie_header") self._cookies_lock.acquire() try: self._policy._now = self._now = int(time.time()) cookies = self._cookies_for_request(request) attrs = self._cookie_attrs(cookies) if attrs: if not request.has_header("Cookie"): request.add_unredirected_header( "Cookie", "; ".join(attrs)) # if necessary, advertise that we know RFC 2965 if (self._policy.rfc2965 and not self._policy.hide_cookie2 and not request.has_header("Cookie2")): for cookie in cookies: if cookie.version != 1: request.add_unredirected_header("Cookie2", '$Version="1"') break finally: self._cookies_lock.release() self.clear_expired_cookies()
Example #18
Source File: request.py From blackmamba with MIT License | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #19
Source File: request.py From blackmamba with MIT License | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #20
Source File: request.py From blackmamba with MIT License | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #21
Source File: request.py From addon with GNU General Public License v3.0 | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #22
Source File: request.py From addon with GNU General Public License v3.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("utf8") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #23
Source File: request.py From addon with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #24
Source File: request.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp
Example #25
Source File: request.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.headers.get(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #26
Source File: request.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #27
Source File: request.py From ironpython3 with Apache License 2.0 | 5 votes |
def do_request_(self, request): host = request.host if not host: raise URLError('no host given') if request.data is not None: # POST data = request.data if isinstance(data, str): msg = "POST data should be bytes or an iterable of bytes. " \ "It cannot be of type str." raise TypeError(msg) if not request.has_header('Content-type'): request.add_unredirected_header( 'Content-type', 'application/x-www-form-urlencoded') if not request.has_header('Content-length'): try: mv = memoryview(data) except TypeError: if isinstance(data, collections.Iterable): raise ValueError("Content-Length should be specified " "for iterable data of type %r %r" % (type(data), data)) else: request.add_unredirected_header( 'Content-length', '%d' % (len(mv) * mv.itemsize)) sel_host = host if request.has_proxy(): scheme, sel = splittype(request.selector) sel_host, sel_path = splithost(sel) if not request.has_header('Host'): request.add_unredirected_header('Host', sel_host) for name, value in self.parent.addheaders: name = name.capitalize() if not request.has_header(name): request.add_unredirected_header(name, value) return request
Example #28
Source File: request.py From verge3d-blender-addon with GNU General Public License v3.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val
Example #29
Source File: request.py From ironpython3 with Apache License 2.0 | 5 votes |
def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.get_header(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None
Example #30
Source File: request.py From ironpython3 with Apache License 2.0 | 5 votes |
def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val