Python requests.auth 模块,_basic_auth_str() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用requests.auth._basic_auth_str()

项目:trip    作者:littlecodersh    | 项目源码 | 文件源码
def get_proxy_headers(proxy):
    """Returns a dictionary of the headers to add to any request sent
    through a proxy. This works with urllib3 magic to ensure that they are
    correctly sent to the proxy, rather than in a tunnelled request if
    CONNECT is being used.

    :param proxies: The url of the proxy being used for this request.
    :rtype: dict
    """
    headers = {}
    username, password = get_auth_from_url(proxy)

    if username:
        headers['Proxy-Authorization'] = _basic_auth_str(username,
                                                         password)

    return headers
项目:trip    作者:littlecodersh    | 项目源码 | 文件源码
def rebuild_proxies(self, prepared_request, proxies):
        """This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).

        This method also replaces the Proxy-Authorization header where
        necessary.

        :rtype: dict
        """
        proxies = proxies if proxies is not None else {}
        headers = prepared_request.headers
        url = prepared_request.url
        scheme = urlparse(url).scheme
        new_proxies = proxies.copy()
        no_proxy = proxies.get('no_proxy')

        bypass_proxy = should_bypass_proxies(url, no_proxy=no_proxy)
        # if self.trust_env and not bypass_proxy:
        #     environ_proxies = get_environ_proxies(url, no_proxy=no_proxy)
        # 
        #     proxy = environ_proxies.get(scheme, environ_proxies.get('all'))
        # 
        #     if proxy:
        #         new_proxies.setdefault(scheme, proxy)

        if 'Proxy-Authorization' in headers:
            del headers['Proxy-Authorization']

        try:
            username, password = get_auth_from_url(new_proxies[scheme])
        except KeyError:
            username, password = None, None

        if username and password:
            headers['Proxy-Authorization'] = _basic_auth_str(username, password)

        return new_proxies
项目:ruffruffs    作者:di    | 项目源码 | 文件源码
def test_basic_auth_str_is_always_native(self):
        s = _basic_auth_str("test", "test")
        assert isinstance(s, builtin_str)
        assert s == "Basic dGVzdDp0ZXN0"
项目:filegardener    作者:smorin    | 项目源码 | 文件源码
def test_basic_auth_str_is_always_native(self):
        s = _basic_auth_str("test", "test")
        assert isinstance(s, builtin_str)
        assert s == "Basic dGVzdDp0ZXN0"
项目:filegardener    作者:smorin    | 项目源码 | 文件源码
def test_basic_auth_str_is_always_native(self):
        s = _basic_auth_str("test", "test")
        assert isinstance(s, builtin_str)
        assert s == "Basic dGVzdDp0ZXN0"
项目:Codeforces-Sublime-Plugin    作者:karunk    | 项目源码 | 文件源码
def test_basic_auth_str_is_always_native(self):
        s = _basic_auth_str("test", "test")
        assert isinstance(s, builtin_str)
        assert s == "Basic dGVzdDp0ZXN0"