本文整理匯總了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