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