diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index 508ae02439..40c77ae30e 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -1,10 +1,10 @@ import asyncio +import ssl from typing import Optional, Any, Union, TypedDict, Iterable import aiohttp import numpy as np import scalecodec -import typer from bittensor_wallet import Wallet from bittensor_wallet.utils import SS58_FORMAT from numpy.typing import NDArray @@ -134,7 +134,13 @@ async def __aenter__(self): logging.error( f"Error: Timeout occurred connecting to substrate. Verify your chain and network settings: {self}" ) - raise typer.Exit(code=1) + raise ConnectionError + except (ConnectionRefusedError, ssl.SSLError) as error: + logging.error( + f"Error: Connection refused when connecting to substrate. " + f"Verify your chain and network settings: {self}. Error: {error}" + ) + raise ConnectionError async def __aexit__(self, exc_type, exc_val, exc_tb): await self.substrate.close() @@ -245,7 +251,7 @@ async def get_total_subnets( module="SubtensorModule", storage_function="TotalNetworks", params=[], - block_hash=block_hash + block_hash=block_hash, ) return result @@ -1298,7 +1304,7 @@ async def get_uid_for_hotkey_on_subnet( module="SubtensorModule", storage_function="Uids", params=[netuid, hotkey_ss58], - block_hash=block_hash + block_hash=block_hash, ) # extrinsics diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index fcbb4147d7..61a3c39389 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -23,6 +23,7 @@ import argparse import copy import socket +import ssl from typing import Union, Optional, TypedDict, Any import numpy as np @@ -231,7 +232,7 @@ def _get_substrate(self): except (AttributeError, TypeError, socket.error, OSError) as e: logging.warning(f"Error setting timeout: {e}") - except ConnectionRefusedError as error: + except (ConnectionRefusedError, ssl.SSLError) as error: logging.error( f"Could not connect to {self.network} network with {self.chain_endpoint} chain endpoint.", )