本文整理匯總了Python中requests.adapters.HTTPAdapter.max_retries方法的典型用法代碼示例。如果您正苦於以下問題:Python HTTPAdapter.max_retries方法的具體用法?Python HTTPAdapter.max_retries怎麽用?Python HTTPAdapter.max_retries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類requests.adapters.HTTPAdapter
的用法示例。
在下文中一共展示了HTTPAdapter.max_retries方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from requests.adapters import HTTPAdapter [as 別名]
# 或者: from requests.adapters.HTTPAdapter import max_retries [as 別名]
def __init__(self, config):
self.config = config
self.pool_manager = requests.Session()
self.retry_methods = frozenset(['GET', 'HEAD', 'DELETE', 'OPTIONS'])
# noinspection PyTypeChecker
adapter = HTTPAdapter(
pool_connections=config.http_pool_connections,
pool_maxsize=config.http_pool_size,
# max_retries=Retry(
# method_whitelist=self.retry_methods,
# total=config.http_max_retries,
# connect=config.http_max_retries,
# read=config.http_max_retries,
# status_forcelist=range(500, 600)
# ),
# pool_block=True
)
adapter.max_retries = config.http_max_retries
self.pool_manager.mount('https://', adapter)
self.pool_manager.mount('http://', adapter)
self.pool_manager.verify = bool(self.config.verify_ssl)
示例2: send
# 需要導入模塊: from requests.adapters import HTTPAdapter [as 別名]
# 或者: from requests.adapters.HTTPAdapter import max_retries [as 別名]
def send(self):
self.url = "%s%s" % (self.base_url, self.path)
prepped = self.prepare()
s = Session()
# print(self.data)
h = HTTPAdapter()
h.max_retries = 10
s.mount('http://', h)
s.mount('https://', h)
response = s.send(prepped)
response.needs_user_token = self.needs_user_token
response.original_request = self
return response
示例3: __init__
# 需要導入模塊: from requests.adapters import HTTPAdapter [as 別名]
# 或者: from requests.adapters.HTTPAdapter import max_retries [as 別名]
def __init__(self, app_id):
self.app_id = app_id
# Provides cookie persistence, connection-pooling, and configuration.
self.session = requests.Session()
# Create an requests HTTP adapter and set number of retries to attempt
adapter = HTTPAdapter()
adapter.max_retries = 5
# Register transport adapter for given URL prefix and enable connection retrying.
self.session.mount(self.API_URL_PREFIX, adapter=adapter)