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


Python exceptions.ProtocolError方法代码示例

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


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

示例1: get_ord_book

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def get_ord_book(self, pair):
        error_count = 0
        book_returned = False
        ord_book = {}
        fail = False
        self.lg.log('Getting order book for pair ' + pair)

        while not book_returned and not fail:
            try:
                ord_book = client.depth(pair, limit=5)
            except (MalformedRequest, InternalError, StatusUnknown,
                    ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__) + ' ' + 'Order book retrieve for ' + pair +
                            ' failed, keep trying')
                error_count += 1
                time.sleep(1)
                client.set_offset()
            else:
                book_returned = True
            finally:
                if error_count >= 5:
                    self.lg.log("Tried to get order book 5 times and failed")
                    fail = True
        return {"ord_book": ord_book, "fail_flag": fail} 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:26,代码来源:mult_arbit.py

示例2: get_open_ords

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def get_open_ords(self, pair):
        error_count = 0
        got_ords = False
        open_ords = {}
        # self.lg.log('Getting open orders for pair ' + pair)
        while not got_ords and error_count < 10:
            try:
                open_ords = client.openOrders(pair)
            except (
            MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError,
            HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__) + ' ' + 'Open order request failed try again')
                error_count += 1
                time.sleep(1)
                client.set_offset()
            else:
                got_ords = True
            finally:
                if error_count >= 10:
                    self.lg.log('Open orders check failed 10 times')
        return open_ords 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:23,代码来源:mult_arbit.py

示例3: route_check_altfirst

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def route_check_altfirst(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        calc_done = False
        route_gain = -1
        bid_p1 = -1
        ask_p2 = -1
        bid_p3 = -1
        while calc_done == False:
            try:
                bid_p1 = float(client.depth(pair_1, limit = 5)['bids'][0][0])
                ask_p2 = float(client.depth(pair_2, limit = 5)['asks'][0][0])
                bid_p3 = float(client.depth(pair_3, limit = 5)['bids'][0][0])
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = (1 / (bid_p1 + pair_1_pip)) * (ask_p2 - pair_2_pip)  / (bid_p3 + pair_3_pip)
                calc_done = True

        return (route_gain, bid_p1, ask_p2, bid_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:21,代码来源:data_checks.py

示例4: route_check_altlast

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def route_check_altlast(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        calc_done = False
        route_gain = -1
        bid_p2 = -1
        ask_p3 = -1
        ask_p1 = -1
        while calc_done == False:
            try:
                ask_p1 = float(client.depth(pair_1, limit = 5)['asks'][0][0]) - float(pair_1_pip)
                bid_p2 = float(client.depth(pair_2, limit = 5)['bids'][0][0]) + float(pair_2_pip)
                ask_p3 = float(client.depth(pair_3, limit = 5)['asks'][0][0]) - float(pair_3_pip)
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                # route_gain = ((ask_p1 - pair_1_pip) / ((bid_p2 + pair_2_pip)) * (ask_p3 - pair_3_pip))
                route_gain = ask_p1  / bid_p2 * ask_p3
                calc_done = True
        return (route_gain, ask_p1, bid_p2, ask_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:21,代码来源:data_checks.py

示例5: route_check_alt_last_lastprice

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def route_check_alt_last_lastprice(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        route_gain = -1
        calc_done = False
        t_1_price = -1
        t_2_price = -1
        t_3_price = -1
        while calc_done == False:
            try:
                prices = client.allPrices()
                for p in prices:
                    symbol = p['symbol']
                    if symbol == pair_1:
                        t_1_price =  float(p['price'])
                    if symbol == pair_2:
                        t_2_price =  float(p['price'])
                    if symbol == pair_3:
                        t_3_price =  float(p['price'])
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = (t_1_price / (t_2_price) * t_3_price)
                calc_done = True

        return route_gain 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:27,代码来源:data_checks.py

示例6: route_check_t3_ask_oth_lastprice

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def route_check_t3_ask_oth_lastprice(self, pair_1, pair_2, pair_3, pair_1_pip, pair_2_pip, pair_3_pip):
        route_gain = -1
        ask_p3 = -1
        calc_done = False
        t_1_price = -1
        t_2_price = -1
        while calc_done == False:
            try:
                prices = client.allPrices()
                for p in prices:
                    symbol = p['symbol']
                    if symbol == pair_1:
                        t_1_price = float(p['price']) - pair_1_pip
                    if symbol == pair_2:
                        t_2_price = float(p['price']) + pair_2_pip

                ask_p3 = float(client.depth(pair_3, limit=5)['asks'][0][0]) - pair_3_pip
            except (MalformedRequest, InternalError, StatusUnknown, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(str(e) + ' ' + str(e.__traceback__))
                client.set_offset()
            else:
                route_gain = t_1_price / t_2_price * ask_p3
                calc_done = True

        return (route_gain, t_1_price, t_2_price, ask_p3) 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:27,代码来源:data_checks.py

示例7: set_offset

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def set_offset(self):
        got_time = False
        while not got_time:
            try:
                cur_time = int(time.time() * 1000)
                bintime = int(self.time()['serverTime'])
                time_diff = cur_time - bintime
                if time_diff > 0:
                    self.time_offset = time_diff
                else:
                    self.time_offset = 500
            except (InternalError, StatusUnknown,
                        ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                print(str(e) + ' ' + str(e.__traceback__) + 'Time check failed, retry')
                time.sleep(.5)
            else:
                got_time = True 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:19,代码来源:api.py

示例8: _load_server_info

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def _load_server_info(self):
        def just_json(_, serialized):
            return serialized

        if not self._cache.get('version'):
            try:
                self._cache['version'] = {
                    'kubernetes': self.client.request('get', '/version', serializer=just_json)
                }
            except (ValueError, MaxRetryError) as e:
                if isinstance(e, MaxRetryError) and not isinstance(e.reason, ProtocolError):
                    raise
                if not self.client.configuration.host.startswith("https://"):
                    raise ValueError("Host value %s should start with https:// when talking to HTTPS endpoint" %
                                     self.client.configuration.host)
                else:
                    raise

        self.__version = self._cache['version'] 
开发者ID:kubernetes-client,项目名称:python-base,代码行数:21,代码来源:discovery.py

示例9: _watch_resource_loop

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def _watch_resource_loop(mode, *args):
    while True:
        try:
            # Always wait to slow down the loop in case of exceptions
            sleep(os.getenv("ERROR_THROTTLE_SLEEP", 5))
            if mode == "SLEEP":
                listResources(*args)
                sleep(os.getenv("SLEEP_TIME", 60))
            else:
                _watch_resource_iterator(*args)
        except ApiException as e:
            if e.status != 500:
                print(f"{timestamp()} ApiException when calling kubernetes: {e}\n")
            else:
                raise
        except ProtocolError as e:
            print(f"{timestamp()} ProtocolError when calling kubernetes: {e}\n")
        except MaxRetryError as e:
            print(f"{timestamp()} MaxRetryError when calling kubernetes: {e}\n")
        except Exception as e:
            print(f"{timestamp()} Received unknown exception: {e}\n") 
开发者ID:kiwigrid,项目名称:k8s-sidecar,代码行数:23,代码来源:resources.py

示例10: errormanager

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def errormanager(func):
    """
    Menangkap spesifikasi pengecualian
    """

    globals()["RETRY_COUNT"] = 0

    @functools.wraps(func)
    def decorated(*args, **kwargs):
        global RETRY_COUNT

        try:
            return func(*args, **kwargs)

        except ProtocolError as e:
            # XXX: abaikan ?
            pass

        except Exception as e:
            if issubclass(e.__class__, BrutemapException):
                raise

            time.sleep(SETTING.DELAY)
            logger.error("Error occurred: %s" % str(e))

            if RETRY_COUNT != SETTING.MAX_RETRY:
                RETRY_COUNT += 1
                return decorated(*args, **kwargs)

            raise

    return decorated 
开发者ID:brutemap-dev,项目名称:brutemap,代码行数:34,代码来源:manager.py

示例11: _fetch_inventory

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def _fetch_inventory(self, inventory_url: str) -> Optional[dict]:
        """Get and return inventory from `inventory_url`. If fetching fails, return None."""
        fetch_func = functools.partial(intersphinx.fetch_inventory, SPHINX_MOCK_APP, '', inventory_url)
        for retry in range(1, FAILED_REQUEST_RETRY_AMOUNT+1):
            try:
                package = await self.bot.loop.run_in_executor(None, fetch_func)
            except ConnectTimeout:
                log.error(
                    f"Fetching of inventory {inventory_url} timed out,"
                    f" trying again. ({retry}/{FAILED_REQUEST_RETRY_AMOUNT})"
                )
            except ProtocolError:
                log.error(
                    f"Connection lost while fetching inventory {inventory_url},"
                    f" trying again. ({retry}/{FAILED_REQUEST_RETRY_AMOUNT})"
                )
            except HTTPError as e:
                log.error(f"Fetching of inventory {inventory_url} failed with status code {e.response.status_code}.")
                return None
            except ConnectionError:
                log.error(f"Couldn't establish connection to inventory {inventory_url}.")
                return None
            else:
                return package
        log.error(f"Fetching of inventory {inventory_url} failed.")
        return None 
开发者ID:python-discord,项目名称:bot,代码行数:28,代码来源:doc.py

示例12: _load_server_info

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def _load_server_info(self):
        def just_json(_, serialized):
            return serialized

        if not self._cache.get('version'):
            try:
                self._cache['version'] = {
                    'kubernetes': self.client.request('get', '/version', serializer=just_json)
                }
            except (ValueError, MaxRetryError) as e:
                if isinstance(e, MaxRetryError) and not isinstance(e.reason, ProtocolError):
                    raise
                if not self.client.configuration.host.startswith("https://"):
                    raise ValueError("Host value %s should start with https:// when talking to HTTPS endpoint" %
                                     self.client.configuration.host)
                else:
                    raise
            try:
                self._cache['version']['openshift'] = self.client.request(
                    'get',
                    '/version/openshift',
                    serializer=just_json,
                )
            except ApiException:
                pass
        self.__version = self._cache['version'] 
开发者ID:openshift,项目名称:openshift-restclient-python,代码行数:28,代码来源:discovery.py

示例13: create_webdriver_with_retry

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def create_webdriver_with_retry(self, *args, **kwargs):
        """Call the Create Webdriver keyword.

        Retry on connection resets which can happen if custom domain propagation is slow.
        """
        # Get selenium without referencing selenium.driver which doesn't exist yet
        selenium = self.builtin.get_library_instance("SeleniumLibrary")
        for _ in range(12):
            try:
                return selenium.create_webdriver(*args, **kwargs)
            except ProtocolError:
                # Give browser some more time to start up
                time.sleep(5)
        raise Exception("Could not connect to remote webdriver after 1 minute") 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:16,代码来源:Salesforce.py

示例14: main

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--log-level", default=LOG_LEVEL)
    args = parser.parse_args()

    log_level = args.log_level.upper()
    logging.basicConfig(format="%(asctime)s %(message)s", level=log_level)
    logging.debug("log_level: %s" % log_level)

    try:
        config.load_incluster_config()
    except:
        config.load_kube_config()

    while True:
        try:
            watch_loop()
        except ApiException as e:
            logging.error(
                "Exception when calling CoreV1Api->list_event_for_all_namespaces: %s\n"
                % e
            )
            time.sleep(5)
        except ProtocolError:
            logging.warning("ProtocolError exception. Continuing...")
        except Exception as e:
            logging.exception("Unhandled exception occurred.") 
开发者ID:getsentry,项目名称:sentry-kubernetes,代码行数:29,代码来源:sentry-kubernetes.py

示例15: place_order_onetry

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ProtocolError [as 别名]
def place_order_onetry(self, pair, quant, price, side, test=False):
        status = 'not_placed'
        orderID = '0'
        trade = {}

        if test:
            self.lg.log('Would have placed order as: pair = ' + pair + ', quant = ' + str(quant) + ', price = '
                        + str(price) + ', side = ' + side)
            status = 'was_tested'
        elif not test:
            self.lg.log('Placing order as pair = ' + pair + ', quant = ' + str(quant) + ', price = '
                        + str(price) + ', side = ' + side)
            try:
                if side == 'sell':
                    trade = client.newLimitSellOrder(pair, quant, price)
                elif side == 'buy':
                    trade = client.newLimitBuyOrder(pair, quant, price)
            except MalformedRequest as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + ' Tried to place order as pair = ' + pair + ', quant = '
                    + str(quant) + ', price = ' + str(price) + ', side = ' + side)
                client.set_offset()
            except StatusUnknown as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + 'API returned StatusUnknown, checking for placed order')
                order = self.check_for_open(pair)
                fail = order["fail_flag"]
                if not fail:
                    orderID = order["order_ID"]
                    status = order["status"]
            except (InternalError, ConnectionError, RemoteDisconnected, ProtocolError, HTTPException) as e:
                self.lg.log(
                    str(e) + ' ' + str(e.__traceback__) + " Some sort of connection or internal error occured")
            else:
                status = trade["status"]
                orderID = trade["orderId"]
        self.lg.log('Returning: orderID = ' + str(orderID) + ', status = ' + status)
        return {"orderID": orderID, "status": status} 
开发者ID:Reidmcc,项目名称:Binance-bot,代码行数:40,代码来源:mult_arbit.py


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