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


Python adapters.HTTPAdapter方法代碼示例

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


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

示例1: requests_retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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: connect

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def connect(self):

        if self.session is None:

            # Creating a session that can later be re-use to configure custom mechanisms
            self.session = requests.Session()

            # If we specified some retries, we provide a predefined retry-logic
            if self.retries > 0:
                adapter = HTTPAdapter(
                    max_retries=Retry(
                        total=self.retries,
                        backoff_factor=0.1,
                        status_forcelist=[500, 502, 503, 504],
                    )
                )
                for prefix in "http://", "https://":
                    self.session.mount(prefix, adapter)
        else:
            raise TransportAlreadyConnected("Transport is already connected") 
開發者ID:graphql-python,項目名稱:gql,代碼行數:22,代碼來源:requests.py

示例3: requests_retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例4: get_requests_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def get_requests_session(self):
        requests_session = self._session.GetParameter("requests_session")
        if requests_session == None:
            # To make sure we can use the requests session in the threadpool we
            # need to make sure that the connection pool can block. Otherwise it
            # will raise when it runs out of connections and the threads will be
            # terminated.
            requests_session = requests.Session()
            requests_session.mount("https://", adapters.HTTPAdapter(
                pool_connections=10, pool_maxsize=300, max_retries=10,
                pool_block=True))

            requests_session.mount("http://", adapters.HTTPAdapter(
                pool_connections=10, pool_maxsize=300, max_retries=10,
                pool_block=True))

            self._session.SetCache("requests_session", requests_session)

        return requests_session 
開發者ID:google,項目名稱:rekall,代碼行數:21,代碼來源:http_location.py

示例5: __init__

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def __init__(self, endpoint, session_id=None, req_session=None, args=None):
        self._endpoint = endpoint.rstrip('/')
        self._session_id = session_id
        self._args = args or dict()
        # dict structure: {tileable_key -> graph_key, tileable_ids}
        # dict value is a tuple object which records graph key and tileable id
        self._executed_tileables = dict()

        self._serial_type = None
        self._pickle_protocol = pickle.HIGHEST_PROTOCOL

        if req_session:
            self._req_session = req_session
        else:
            import requests
            from requests.adapters import HTTPAdapter

            self._req_session = requests.Session()
            self._req_session.mount('http://stackoverflow.com', HTTPAdapter(max_retries=5))

        self._main() 
開發者ID:mars-project,項目名稱:mars,代碼行數:23,代碼來源:session.py

示例6: get_sync_result

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def get_sync_result(result_payload: dict, sleep_time: int) -> dict:
    # создаём сессию
    session = requests.Session()
    # выставляем кол-во попыток подключения к серверу при ошибке
    session.mount("http://", HTTPAdapter(max_retries=5))
    session.mount("https://", HTTPAdapter(max_retries=5))
    session.verify = False

    while True:
        captcha_response = session.post(get_result_url, json=result_payload).json()

        if captcha_response["errorId"] == 0:
            if captcha_response["status"] == "processing":
                time.sleep(sleep_time)
            else:
                captcha_response.update({"taskId": result_payload["taskId"]})
                session.close()
                return captcha_response
        else:
            captcha_response.update({"taskId": result_payload["taskId"]})
            session.close()
            return captcha_response 
開發者ID:AndreiDrang,項目名稱:python3-anticaptcha,代碼行數:24,代碼來源:get_answer.py

示例7: retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def retry_session(retries=3, backoff_factor=0.8, status_forcelist=(500, 502, 504)):
    """Add retry to Requests Session.

    https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#urllib3.util.retry.Retry
    """
    session = Session()
    retries = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=backoff_factor,
        status_forcelist=status_forcelist,
    )
    # mount all https requests
    session.mount('https://', HTTPAdapter(max_retries=retries))
    return session 
開發者ID:ThreatConnect-Inc,項目名稱:tcex,代碼行數:18,代碼來源:tokens.py

示例8: get_retrying_requests_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例9: retry

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例10: __init__

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def __init__(self, loginer=None, use_proxy=False):
        self.loginer = loginer
        self.use_proxy = use_proxy
        if use_proxy:
            self.proxy_pool = ProxyPool()
            if len(self.proxy_pool) == 0:
                self.use_proxy = False
        self._cookies = None

        self._headers = dict()
        self._headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
        self._headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
        self._headers["Accept-Encoding"] = "gzip, deflate, sdch"
        self._headers["Accept-Language"] = "zh-CN,zh;q=0.8"
        self._request_retry = HTTPAdapter(max_retries=3)

        cookie_dict = dict()
        self._cookies = cookie_dict

    # def init_loginer(self, account, password):
    #     self._cookies = self.loginer.login(account, password)
    #
    # def set_cookies(self, cookies):
    #     self._cookies = cookies 
開發者ID:DarkSand,項目名稱:fetchman,代碼行數:26,代碼來源:requests_downloader.py

示例11: requests_retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例12: init_poolmanager

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [as 別名]
def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):
        """Initializes a urllib3 PoolManager. This method should not be called
        from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param connections: The number of urllib3 connection pools to cache.
        :param maxsize: The maximum number of connections to save in the pool.
        :param block: Block when no free connections are available.
        """
        # save these values for pickling
        self._pool_connections = connections
        self._pool_maxsize = maxsize
        self._pool_block = block

        self.poolmanager = AsyncPoolManager(num_pools=connections, maxsize=maxsize, block=block)
        self.connections = [] 
開發者ID:plexinc,項目名稱:plex-for-kodi,代碼行數:18,代碼來源:asyncadapter.py

示例13: _requests_retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例14: requests_retry_session

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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

示例15: get_docker_client

# 需要導入模塊: from requests import adapters [as 別名]
# 或者: from requests.adapters import HTTPAdapter [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


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