当前位置: 首页>>代码示例>>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;未经允许,请勿转载。