當前位置: 首頁>>代碼示例>>Python>>正文


Python request.add_unredirected_header方法代碼示例

本文整理匯總了Python中urllib.request.add_unredirected_header方法的典型用法代碼示例。如果您正苦於以下問題:Python request.add_unredirected_header方法的具體用法?Python request.add_unredirected_header怎麽用?Python request.add_unredirected_header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib.request的用法示例。


在下文中一共展示了request.add_unredirected_header方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_unredirected_header

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
def add_unredirected_header(self, key, val):
        # will not be added to a redirected request
        self.unredirected_hdrs[key.capitalize()] = val 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:5,代碼來源:request.py

示例2: retry_http_basic_auth

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
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 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:13,代碼來源:request.py

示例3: retry_http_digest_auth

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
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 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:13,代碼來源:request.py

示例4: add_cookie_header

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:34,代碼來源:cookiejar.py

示例5: retry_http_basic_auth

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
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 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:request.py

示例6: http_request

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import add_unredirected_header [as 別名]
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 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:request.py


注:本文中的urllib.request.add_unredirected_header方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。