当前位置: 首页>>代码示例>>Python>>正文


Python util.Retry方法代码示例

本文整理汇总了Python中urllib3.util.Retry方法的典型用法代码示例。如果您正苦于以下问题:Python util.Retry方法的具体用法?Python util.Retry怎么用?Python util.Retry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib3.util的用法示例。


在下文中一共展示了util.Retry方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_retrying_requests_session

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def get_retrying_requests_session(client_statuses=HTTP_CLIENT_STATUS_RETRY,
                                  times=HTTP_MAX_RETRIES, delay=HTTP_BACKOFF_FACTOR,
                                  method_whitelist=None, raise_on_status=True):
    if _http_retries_disabled():
        times = 0

    retry = Retry(
        total=int(times),
        backoff_factor=delay,
        status_forcelist=client_statuses,
        method_whitelist=method_whitelist
    )

    # raise_on_status was added later to Retry, adding compatibility to work
    # with newer versions and ignoring this option with older ones
    if hasattr(retry, 'raise_on_status'):
        retry.raise_on_status = raise_on_status

    session = SessionWithTimeout()
    session.mount('http://', HTTPAdapter(max_retries=retry))
    session.mount('https://', HTTPAdapter(max_retries=retry))

    return session 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:25,代码来源:retries.py

示例2: test_stream_logs_not_decoded

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def test_stream_logs_not_decoded(self, caplog):
        flexmock(Retry).new_instances(fake_retry)
        server = Openshift('http://apis/', 'http://oauth/authorize',
                           k8s_api_url='http://api/v1/')

        logs = (
            u'Lógs'.encode('utf-8'),
            u'Lðgs'.encode('utf-8'),
        )

        fake_response = flexmock(status_code=http_client.OK, headers={})

        (fake_response
            .should_receive('iter_lines')
            .and_yield(*logs)
            .with_args(decode_unicode=False))

        (flexmock(requests)
            .should_receive('request')
            .and_return(fake_response))

        with caplog.at_level(logging.ERROR):
            for result in server.stream_logs('anything'):
                assert isinstance(result, six.binary_type) 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:26,代码来源:test_retries.py

示例3: __init__

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def __init__(self, nodes, **kwargs):
        if kwargs.get('tcp_keepalive', True):
            socket_options = HTTPConnection.default_socket_options + \
                             [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), ]
        else:
            socket_options = HTTPConnection.default_socket_options

        self.http = urllib3.poolmanager.PoolManager(
            num_pools=kwargs.get('num_pools', 10),
            maxsize=kwargs.get('maxsize', 64),
            timeout=kwargs.get('timeout', 30),
            socket_options=socket_options,
            block=False,
            retries=Retry(total=False),
            headers={
                'Content-Type': 'application/json',
                'accept-encoding': 'gzip'},
            cert_reqs='CERT_REQUIRED',
            ca_certs=certifi.where())

        self.nodes = cycle(nodes)
        self.url = ''
        self.request = None
        self.next_node() 
开发者ID:steemit,项目名称:hivemind,代码行数:26,代码来源:http_client.py

示例4: _create_session

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def _create_session(self, max_retries, proxies, backoff_factor, cache):
        sess = Session()
        # Retry only on idempotent methods and only when too many requests
        retries = Retry(
            total=max_retries,
            backoff_factor=backoff_factor,
            status_forcelist=[429],
            method_whitelist=["GET", "UPDATE", "DELETE"],
        )
        retries_adapter = HTTPAdapter(max_retries=retries)
        if cache:
            cache_adapter = CacheControlAdapter(cache_etags=True)
        sess.mount("http://", retries_adapter)
        sess.mount("http://", cache_adapter)
        sess.proxies.update(proxies)
        return sess 
开发者ID:omarryhan,项目名称:pyfy,代码行数:18,代码来源:sync_client.py

示例5: test_fail_after_retries

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def test_fail_after_retries(self, s, status_code, method):
        flexmock(Retry).new_instances(fake_retry)
        # latest python-requests throws OsbsResponseException, 2.6.x - OsbsNetworkException
        with pytest.raises((OsbsNetworkException, OsbsResponseException)) as exc_info:
            s.request(method=method, url='http://httpbin.org/status/%s' % status_code).json()
        if isinstance(exc_info, OsbsResponseException):
            assert exc_info.value.status_code == status_code 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:9,代码来源:test_retries.py

示例6: test_fail_on_first_retry

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def test_fail_on_first_retry(self, s, status_code):
        (flexmock(Retry)
            .should_receive(self.retry_method_name)
            .and_return(True)
            .and_return(False))
        s.get('http://httpbin.org/status/%s' % status_code) 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:8,代码来源:test_http.py

示例7: test_fail_without_retries

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def test_fail_without_retries(self, s, status_code):
        (flexmock(Retry)
            .should_receive(self.retry_method_name)
            .and_return(False))
        (flexmock(Retry)
            .should_receive('increment')
            .never())
        with pytest.raises(OsbsResponseException) as exc_info:
            s.get('http://httpbin.org/drip?numbytes=5&code=%s' % status_code).json()
        assert exc_info.value.status_code == status_code 
开发者ID:containerbuildsystem,项目名称:osbs-client,代码行数:12,代码来源:test_http.py

示例8: __init__

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import Retry [as 别名]
def __init__(self, input, query, log, callback=None, rampage_type=None, conf=None, **kwargs):
        QObject.__init__(self)
        threading.Thread.__init__(self)

        self._input = input
        self._query = query
        self.log = log
        self._callback = callback
        self._rampage_type = rampage_type

        if 'captcha_answer' in kwargs:
            self._captcha_answer = kwargs['captcha_answer']

        if conf:
            self._conf = conf
        else:
            self._conf = Configuration('SciHubEVA.conf')

        self._sess = requests.Session()
        self._sess.headers = json.loads(self._conf.get('network', 'session_header'))

        retry_times = self._conf.getint('network', 'retry_times')
        retry = Retry(total=retry_times, read=retry_times, connect=retry_times)
        adapter = HTTPAdapter(max_retries=retry)
        self._sess.mount('http://', adapter)
        self._sess.mount('https://', adapter)

        self._set_http_proxy()

        self._doi_pattern = re.compile(r'\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'])\S)+)\b')
        self._illegal_filename_pattern = re.compile(r'[\/\\\:\*\?\"\<\>\|]') 
开发者ID:leovan,项目名称:SciHubEVA,代码行数:33,代码来源:scihub_api.py


注:本文中的urllib3.util.Retry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。