當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。