当前位置: 首页>>代码示例>>Python>>正文


Python requests_toolbelt.user_agent方法代码示例

本文整理汇总了Python中requests_toolbelt.user_agent方法的典型用法代码示例。如果您正苦于以下问题:Python requests_toolbelt.user_agent方法的具体用法?Python requests_toolbelt.user_agent怎么用?Python requests_toolbelt.user_agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests_toolbelt的用法示例。


在下文中一共展示了requests_toolbelt.user_agent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_session

# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def get_session(k8s_api_verify_tls):
    global session
    if session is None:
        with open('/var/run/secrets/kubernetes.io/serviceaccount/token') as token_file:
            token = token_file.read()
        session = requests.Session()
        session.headers = {
            'Authorization': 'Bearer ' + token,
            'Content-Type': 'application/json',
            'User-Agent': user_agent('Deis Controller', deis_version)
        }
        if k8s_api_verify_tls:
            session.verify = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
        else:
            session.verify = False
    return session 
开发者ID:deis,项目名称:controller,代码行数:18,代码来源:__init__.py

示例2: get_session

# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def get_session():
    global session
    if session is None:
        session = requests.Session()
        session.headers = {
            # https://toolbelt.readthedocs.org/en/latest/user-agent.html#user-agent-constructor
            'User-Agent': user_agent('Deis Controller', deis_version),
        }
        # `mount` a custom adapter that retries failed connections for HTTP and HTTPS requests.
        # http://docs.python-requests.org/en/latest/api/#requests.adapters.HTTPAdapter
        session.mount('http://', requests.adapters.HTTPAdapter(max_retries=10))
        session.mount('https://', requests.adapters.HTTPAdapter(max_retries=10))
    return session 
开发者ID:deis,项目名称:controller,代码行数:15,代码来源:__init__.py

示例3: user_agent

# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def user_agent(self):
        return user_agent("poetry", __version__) 
开发者ID:python-poetry,项目名称:poetry,代码行数:4,代码来源:uploader.py

示例4: make_session

# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def make_session(self):
        session = requests.session()
        if self.is_authenticated():
            session.auth = (self._username, self._password)

        session.headers["User-Agent"] = self.user_agent
        for scheme in ("http://", "https://"):
            session.mount(scheme, self.adapter)

        return session 
开发者ID:python-poetry,项目名称:poetry,代码行数:12,代码来源:uploader.py

示例5: __init__

# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def __init__(self):
        """Constructs an OptionsIdentity instance."""

        self.auth = None
        self.cookies = requests.cookies.RequestsCookieJar()
        self.headers = requests.utils.default_headers()
        self.headers.update({"User-Agent": user_agent(PackageHelper.get_alias(), PackageHelper.get_version())})
        self.proxies = None 
开发者ID:jerrychan807,项目名称:WSPIH,代码行数:10,代码来源:Options.py


注:本文中的requests_toolbelt.user_agent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。