當前位置: 首頁>>代碼示例>>Python>>正文


Python retry.Retry方法代碼示例

本文整理匯總了Python中requests.packages.urllib3.util.retry.Retry方法的典型用法代碼示例。如果您正苦於以下問題:Python retry.Retry方法的具體用法?Python retry.Retry怎麽用?Python retry.Retry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests.packages.urllib3.util.retry的用法示例。


在下文中一共展示了retry.Retry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: requests_retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def requests_retry_session(
    retries=3,
    backoff_factor=0.3,
    status_forcelist=(500, 502, 504),
    session=None,
):
    session = session or requests.Session()
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
    )
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)
    return session 
開發者ID:makkoncept,項目名稱:yts_torrents,代碼行數:20,代碼來源:yts_am_api.py

示例2: requests_retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def requests_retry_session(
    retries=5,
    backoff_factor=1,
    status_forcelist=[401, 402, 403, 500, 502, 504],
    session=None,
):
    session = session or requests.Session()
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
    )
    adapter = HTTPAdapter(max_retries=retry)
    session.mount("http://", adapter)
    session.mount("https://", adapter)
    return session 
開發者ID:etalab,項目名稱:schema.data.gouv.fr,代碼行數:20,代碼來源:issues.py

示例3: retry

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def retry(num=5):
    """"retry connection.
    
        define max tries num
        if the backoff_factor is 0.1, then sleep() will sleep for
        [0.1s, 0.2s, 0.4s, ...] between retries.
        It will also force a retry if the status code returned is 500, 502, 503 or 504.    
    
    """
    s = requests.Session()
    retries = Retry(total=num, backoff_factor=0.1,
                    status_forcelist=[500, 502, 503, 504])
    s.mount('http://', HTTPAdapter(max_retries=retries))

    return s

# CONSTANT 
開發者ID:zqfang,項目名稱:GSEApy,代碼行數:19,代碼來源:utils.py

示例4: requests_retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def requests_retry_session(
    retries=5,
    backoff_factor=0.3,
    status_forcelist=(502, 504),
    session=None,
):
    session = session or requests.Session()
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
    )
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)
    return session 
開發者ID:rstms,項目名稱:txTrader,代碼行數:20,代碼來源:client.py

示例5: _requests_retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def _requests_retry_session(
        self,
        retries=3,
        backoff_factor=0.3,
        method_whitelist=['HEAD', 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'TRACE'],
        status_forcelist=(500, 502, 503, 504, 520, 524),
        session=None,
    ):
        session = session or requests.Session()
        retry = Retry(
            total=retries,
            read=retries,
            connect=retries,
            status=retries,
            method_whitelist=method_whitelist,
            backoff_factor=backoff_factor,
            status_forcelist=status_forcelist,
        )
        adapter = HTTPAdapter(max_retries=retry)
        session.mount('http://', adapter)
        session.mount('https://', adapter)
        return session 
開發者ID:percy,項目名稱:python-percy-client,代碼行數:24,代碼來源:connection.py

示例6: requests_retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def requests_retry_session(
    retries=3,
    backoff_factor=0.3,
    status_forcelist=(502, 504),
    session=None,
    **kwargs
):
    session = session or requests.Session()
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
    )
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)
    return session 
開發者ID:sparkplug,項目名稱:momoapi-python,代碼行數:21,代碼來源:utils.py

示例7: get_docker_client

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def get_docker_client(base_url=None, retry_read=config.DOCKER_MAX_READ_RETRIES,
                      retry_status_forcelist=(500,)):
    client_key = (retry_read, retry_status_forcelist)
    if client_key not in _DOCKER_CLIENTS:
        client = docker.DockerClient(base_url=base_url or config.DOCKER_URL,
                                     timeout=config.DOCKER_TIMEOUT)
        retries = Retry(total=config.DOCKER_MAX_TOTAL_RETRIES,
                        connect=config.DOCKER_MAX_CONNECT_RETRIES,
                        read=retry_read,
                        method_whitelist=False,
                        status_forcelist=retry_status_forcelist,
                        backoff_factor=config.DOCKER_BACKOFF_FACTOR,
                        raise_on_status=False)
        http_adapter = HTTPAdapter(max_retries=retries)
        client.api.mount('http://', http_adapter)
        _DOCKER_CLIENTS[client_key] = client
    return _DOCKER_CLIENTS[client_key] 
開發者ID:StepicOrg,項目名稱:epicbox,代碼行數:19,代碼來源:utils.py

示例8: send

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def send(self, request, *args, **kwargs):
        content_length_is_unknown = (request.body is not None
                                     and 'Content-Length' not in request.headers)
        if content_length_is_unknown:
            # it seems that requests's HTTPAdapter does not perform
            # retries in such a case, even though they were requested
            # (see the source code of HTTPAdapter.send() in conjunction
            # with urllib3.connectionpool.HTTPConnectionPool.urlopen()
            # and urllib3.util.retry.Retry.increment()...) -- so here
            # we raise an exception to prevent such a silent omission
            # [we analyzed this for requests==2.21.0 and urllib3==1.24.1]
            raise ValueError('non-zero `retries` has been specified and, '
                             'at the same time, Content-Length of the request '
                             'could not be determined (suggested solutions: '
                             'specify `data` whose length is discoverable, '
                             'or specify `retries=0`)')

        return super(_HTTPAdapterForRetries, self).send(request, *args, **kwargs) 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:20,代碼來源:http_helpers.py

示例9: _init_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def _init_session(session, **kwargs):
    if session is None:
        if kwargs.get('asynchronous'):
            session = FuturesSession(max_workers=kwargs.get('max_workers', 8))
        else:
            session = Session()
        if kwargs.get('proxies'):
            session.proxies = kwargs.get('proxies')
        retries = Retry(
            total=3,
            backoff_factor=1,
            status_forcelist=[429, 500, 502, 503, 504],
            method_whitelist=["HEAD", "GET", "OPTIONS", "POST", "TRACE"])
        session.mount('https://', TimeoutHTTPAdapter(
            max_retries=retries,
            timeout=kwargs.get('timeout', DEFAULT_TIMEOUT)))
        # TODO: Figure out how to utilize this within the validate_response
        # TODO: This will be a much better way of handling bad requests than
        # TODO: what I'm currently doing.
        # session.hooks['response'] = \
        #     [lambda response, *args, **kwargs: response.raise_for_status()]
        session.headers.update({
            "User-Agent": random.choice(USER_AGENT_LIST)
        })
    return session 
開發者ID:dpguthrie,項目名稱:yahooquery,代碼行數:27,代碼來源:__init__.py

示例10: retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def retry_session():
    """Get a Requests session that retries HTTP and HTTPS requests.
    """
    # Adapted from:
    # https://www.peterbe.com/plog/best-practice-with-retries-with-requests
    session = requests.Session()
    retry = Retry(
        total=RETRY_COUNT,
        read=RETRY_COUNT,
        connect=RETRY_COUNT,
        backoff_factor=RETRY_FACTOR,
        status_forcelist=RETRY_STATUSES,
    )
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)
    return session 
開發者ID:beele,項目名稱:HomebridgeLgSmartThinqAirco,代碼行數:19,代碼來源:core.py

示例11: __retry_session

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def __retry_session(self, retries=10, backoff_factor=0.3,
                        status_forcelist=(500, 502, 504),
                        session=None):
        """
        Retry the connection using requests if it fails. Use this as a wrapper
        to request from datapoint
        """

        # requests.Session allows finer control, which is needed to use the
        # retrying code
        the_session = session or requests.Session()

        # The Retry object manages the actual retrying
        retry = Retry(total=retries, read=retries, connect=retries,
                      backoff_factor=backoff_factor,
                      status_forcelist=status_forcelist)

        adapter = HTTPAdapter(max_retries=retry)

        the_session.mount('http://', adapter)
        the_session.mount('https://', adapter)

        return the_session 
開發者ID:EJEP,項目名稱:datapoint-python,代碼行數:25,代碼來源:Manager.py

示例12: get_simple_salesforce_connection

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def get_simple_salesforce_connection(project_config, org_config, api_version=None):
    # Retry on long-running metadeploy jobs
    retries = Retry(total=5, status_forcelist=(502, 503, 504), backoff_factor=0.3)
    adapter = HTTPAdapter(max_retries=retries)

    sf = simple_salesforce.Salesforce(
        instance_url=org_config.instance_url,
        session_id=org_config.access_token,
        version=api_version or project_config.project__package__api_version,
    )
    try:
        app = project_config.keychain.get_service("connectedapp")
        client_name = app.client_id
    except (ServiceNotValid, ServiceNotConfigured):
        client_name = "CumulusCI/{}".format(__version__)

    sf.headers.setdefault(CALL_OPTS_HEADER_KEY, "client={}".format(client_name))
    sf.session.mount("http://", adapter)
    sf.session.mount("https://", adapter)

    return sf 
開發者ID:SFDO-Tooling,項目名稱:CumulusCI,代碼行數:23,代碼來源:utils.py

示例13: test_client_request_timeout_when_connection_retry_configuration_specified

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def test_client_request_timeout_when_connection_retry_configuration_specified(self):
        connection_policy = documents.ConnectionPolicy()
        # making timeout 0 ms to make sure it will throw
        connection_policy.RequestTimeout = 0
        connection_policy.ConnectionRetryConfiguration = Retry(
                                                            total=3,
                                                            read=3,
                                                            connect=3,
                                                            backoff_factor=0.3,
                                                            status_forcelist=(500, 502, 504)
                                                        )
        with self.assertRaises(Exception):
            # client does a getDatabaseAccount on initialization, which will time out
            cosmos_client.CosmosClient(CRUDTests.host,
                                                {'masterKey': CRUDTests.masterKey},
                                                connection_policy) 
開發者ID:Azure,項目名稱:azure-cosmos-python,代碼行數:18,代碼來源:crud_tests.py

示例14: initialize_client_with_connection_retry_config

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def initialize_client_with_connection_retry_config(self, retries):
        connection_policy = documents.ConnectionPolicy()
        connection_policy.ConnectionRetryConfiguration = Retry(
                                                            total=retries,
                                                            read=retries,
                                                            connect=retries,
                                                            backoff_factor=0.3,
                                                            status_forcelist=(500, 502, 504)
                                                        )
        start_time = time.time()
        try:
            cosmos_client.CosmosClient("https://localhost:9999",
                                                {'masterKey': CRUDTests.masterKey},
                                                connection_policy)
            self.fail()
        except ConnectionError as e:
            end_time = time.time()
            return end_time - start_time 
開發者ID:Azure,項目名稱:azure-cosmos-python,代碼行數:20,代碼來源:crud_tests.py

示例15: decode

# 需要導入模塊: from requests.packages.urllib3.util import retry [as 別名]
# 或者: from requests.packages.urllib3.util.retry import Retry [as 別名]
def decode(key: str, string: str) -> str:
    string = base64.urlsafe_b64decode(string.encode() + b'===')
    string = string.decode('latin')
    encoded_chars = []
    for i in range(len(string)):
        key_c = key[i % len(key)]
        encoded_c = chr((ord(string[i]) - ord(key_c) + 256) % 256)
        encoded_chars.append(encoded_c)
    encoded_string = ''.join(encoded_chars)
    return encoded_string

# e = encode('a key', 'a message')
# d = decode('a key', e)
# print([e])
# print([d])


# https://www.peterbe.com/plog/best-practice-with-retries-with-requests
# Provides a requests Session object with requests' Retry capabilities.
# TODO: may make numbers below configurable 
開發者ID:geopython,項目名稱:GeoHealthCheck,代碼行數:22,代碼來源:util.py


注:本文中的requests.packages.urllib3.util.retry.Retry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。