Skip to content

Commit

Permalink
Handle SSL Error on Connection (#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhaleking authored Nov 5, 2024
1 parent d424cd1 commit 43a01a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -134,7 +134,13 @@ async def __aenter__(self):
logging.error(
f"<red>Error</red>: 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"<red>Error</red>: 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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import argparse
import copy
import socket
import ssl
from typing import Union, Optional, TypedDict, Any

import numpy as np
Expand Down Expand Up @@ -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.",
)
Expand Down

0 comments on commit 43a01a7

Please sign in to comment.