本文整理汇总了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)