本文整理汇总了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
示例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
示例3: user_agent
# 需要导入模块: import requests_toolbelt [as 别名]
# 或者: from requests_toolbelt import user_agent [as 别名]
def user_agent(self):
return user_agent("poetry", __version__)
示例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
示例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