當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。