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


Python urllib3.Retry方法代码示例

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


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

示例1: __init__

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def __init__(self, tor_controller=None):
        if not self.__socket_is_patched():
            gevent.monkey.patch_socket()
        self.tor_controller = tor_controller
        if not self.tor_controller:
            retries = urllib3.Retry(35)
            user_agent = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
            self.session = urllib3.PoolManager(maxsize=35,
                                               cert_reqs='CERT_REQUIRED',
                                               ca_certs=certifi.where(),
                                               headers=user_agent,
                                               retries=retries)
        else:
            self.session = self.tor_controller.get_tor_session()
        self.__tor_status__()
        self.languages = self._get_all_languages() 
开发者ID:SekouD,项目名称:mlconjug,代码行数:18,代码来源:cooljugator_scraper.py

示例2: retry_session

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def retry_session(self):
        if not hasattr(self, "_retry_session"):
            self._retry_session = requests.Session()
            retry = Retry(
                total=3,
                read=3,
                connect=3,
                backoff_factor=2,
                status_forcelist=[429, 500, 502, 503, 504],
            )
            adapter = HTTPAdapter(max_retries=retry)
            self._retry_session.mount("http://", adapter)
            self._retry_session.mount("https://", adapter)
            self._threaded_done = 0
            self._threaded_exceptions = 0
            self._periodic_http_done = 0
            self._periodic_http_exceptions = 0
            self._periodic_ws_done = 0
            self._periodic_ws_exceptions = 0
        return self._retry_session 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:22,代码来源:retry_transport.py

示例3: __init__

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def __init__(self) -> None:
        http_client = urllib3.PoolManager(
            timeout=urllib3.Timeout.DEFAULT_TIMEOUT,
            cert_reqs='CERT_REQUIRED',
            ca_certs=certifi.where(),
            retries=urllib3.Retry(
                total=5,
                backoff_factor=0.2,
                status_forcelist=[500, 502, 503, 504]
            ),
            maxsize=20
        )
        self.client = minio.Minio(
            S3_SERVER,
            access_key=S3_ACCESS_KEY,
            secret_key=S3_SECRET_KEY,
            region=S3_REGION,
            secure=S3_SERVER == 's3.amazonaws.com',
            http_client=http_client
        ) 
开发者ID:bosondata,项目名称:chrome-prerender,代码行数:22,代码来源:s3.py

示例4: retry_session

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def retry_session(self):
        if not hasattr(self, '_retry_session'):
            self._retry_session = requests.Session()
            retry = Retry(
                total=3,
                read=3,
                connect=3,
                backoff_factor=2,
                status_forcelist=[429, 500, 502, 503, 504],
            )
            adapter = HTTPAdapter(max_retries=retry)
            self._retry_session.mount('http://', adapter)
            self._retry_session.mount('https://', adapter)
            self._threaded_done = 0
            self._threaded_exceptions = 0
            self._periodic_http_done = 0
            self._periodic_http_exceptions = 0
            self._periodic_ws_done = 0
            self._periodic_ws_exceptions = 0
        return self._retry_session 
开发者ID:polyaxon,项目名称:polyaxon-client,代码行数:22,代码来源:retry_transport.py

示例5: _conn_request

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def _conn_request(self, conn, request_uri, method, body, headers):
        full_uri = self._create_full_uri(conn, request_uri)

        decode = True if method != 'HEAD' else False

        try:
            urllib3_response = self.pool.request(
                method,
                full_uri,
                body=body,
                headers=headers,
                redirect=False,
                retries=urllib3.Retry(total=False, redirect=0),
                timeout=urllib3.Timeout(total=self.timeout),
                decode_content=decode)

            response = _map_response(urllib3_response, decode=decode)
            content = urllib3_response.data

        except Exception as e:
            raise _map_exception(e)

        return response, content 
开发者ID:GoogleCloudPlatform,项目名称:httplib2shim,代码行数:25,代码来源:__init__.py

示例6: post_with_retries

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def post_with_retries(url: str, data: dict, retries: int, backoff: float) -> int:
    """
    Make a POST request with retries.

    >>> post_with_retries('http://httpstat.us/503', {}, retries=1, backoff=0)
    500
    >>> post_with_retries('https://httpstat.us/200', {}, retries=1, backoff=0)
    200
    """
    retry_adapter = HTTPAdapter(max_retries=Retry(
        total=retries,
        backoff_factor=backoff,
        status_forcelist=[500, 502, 503, 504],
        method_whitelist=frozenset(['POST'])
    ))

    with Session() as session:
        session.mount('http://', retry_adapter)
        session.mount('https://', retry_adapter)

        try:
            response = session.post(url, data=data)
        except RetryError:
            return 500

        return response.status_code 
开发者ID:microsoft,项目名称:agogosml,代码行数:28,代码来源:http_request.py

示例7: __init__

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def __init__(self, endpoint=None, http_client=None):
        self._endpoint = endpoint or "http://169.254.169.254"
        self._http_client = http_client or urllib3.PoolManager(
            retries=urllib3.Retry(
                total=5,
                backoff_factor=0.2,
                status_forcelist=[500, 502, 503, 504],
            ),
        ) 
开发者ID:minio,项目名称:minio-py,代码行数:11,代码来源:providers.py

示例8: test_custom_retries

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def test_custom_retries(self):
        RETRIES = Retry(20, backoff_factor=0.1)
        options = {'path': 'test/', 'retries': RETRIES}

        self.factory_custom_proxy_view(**options)
        url = 'http://www.example.com/test/'
        headers = {'Cookie': ''}
        self.urlopen.assert_called_with('GET', url, redirect=False,
                                        retries=RETRIES,
                                        preload_content=False,
                                        decode_content=False,
                                        headers=headers, body=b'') 
开发者ID:danpoland,项目名称:drf-reverse-proxy,代码行数:14,代码来源:test_request.py

示例9: get_session

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def get_session(*args: Any, **kwargs: Any) -> "ForestSession":
    """
    Create a requests session to access the REST API

    :return: requests session
    :rtype: Session
    """
    session = ForestSession(*args, **kwargs)
    retry_adapter = HTTPAdapter(
        max_retries=Retry(
            total=3,
            method_whitelist=["POST"],
            status_forcelist=[502, 503, 504, 521, 523],
            backoff_factor=0.2,
            raise_on_status=False,
        )
    )

    session.mount("http://", retry_adapter)
    session.mount("https://", retry_adapter)

    # We need this to get binary payload for the wavefunction call.
    session.headers.update({"Accept": "application/octet-stream"})

    session.headers.update({"Content-Type": "application/json; charset=utf-8"})

    return session 
开发者ID:rigetti,项目名称:pyquil,代码行数:29,代码来源:_base_connection.py

示例10: get_session

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def get_session(self):
        session = requests.Session()
        retries = Retry(total=self.max_attempts,
                        backoff_factor=self.timeout / 1000,
                        method_whitelist=['POST'],
                        status_forcelist=[202])
        session.mount('https://', HTTPAdapter(max_retries=retries))
        return session 
开发者ID:yandex-money,项目名称:yandex-checkout-sdk-python,代码行数:10,代码来源:client.py

示例11: _build_session

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def _build_session(self):
        self._session = requests.Session()
        retry = urllib3.Retry(
            total=self.retries,
            connect=None,
            read=False,
            status=self.status_retries,
            backoff_factor=self.backoff_factor,
            status_forcelist=self.status_forcelist)

        adapter = requests.adapters.HTTPAdapter(max_retries=retry)
        self._session.mount('http://', adapter)
        self._session.mount('https://', adapter) 
开发者ID:plamere,项目名称:spotipy,代码行数:15,代码来源:client.py

示例12: __init__

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import Retry [as 别名]
def __init__(self, endpoint, access_key=None,
                 secret_key=None,
                 session_token=None,
                 secure=True,
                 region=None,
                 http_client=None,
                 credentials=None):

        # Validate endpoint.
        is_valid_endpoint(endpoint)

        # Validate http client has correct base class.
        if http_client and not isinstance(
                http_client,
                urllib3.poolmanager.PoolManager):
            raise InvalidArgumentError(
                'HTTP client should be of instance'
                ' `urllib3.poolmanager.PoolManager`'
            )

        # Default is a secured connection.
        scheme = 'https://' if secure else 'http://'
        self._region = region or get_s3_region_from_endpoint(endpoint)
        self._region_map = dict()
        self._endpoint_url = urlsplit(scheme + endpoint).geturl()
        self._is_ssl = secure
        self._access_key = access_key
        self._secret_key = secret_key
        self._session_token = session_token
        self._user_agent = _DEFAULT_USER_AGENT
        self._trace_output_stream = None
        self._enable_s3_accelerate = False
        self._accelerate_endpoint_url = scheme + 's3-accelerate.amazonaws.com'
        self._credentials = credentials or Credentials(
            provider=Chain(
                providers=[
                    Static(access_key, secret_key, session_token),
                    EnvAWS(),
                    EnvMinio(),
                ]
            )
        )

        # Load CA certificates from SSL_CERT_FILE file if set
        ca_certs = os.environ.get('SSL_CERT_FILE') or certifi.where()
        self._http = http_client or urllib3.PoolManager(
            timeout=urllib3.Timeout.DEFAULT_TIMEOUT,
            maxsize=MAX_POOL_SIZE,
            cert_reqs='CERT_REQUIRED',
            ca_certs=ca_certs,
            retries=urllib3.Retry(
                total=5,
                backoff_factor=0.2,
                status_forcelist=[500, 502, 503, 504]
            )
        )

    # Set application information. 
开发者ID:minio,项目名称:minio-py,代码行数:60,代码来源:api.py


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