diff --git a/bittensor/__main__.py b/bittensor/__main__.py
index 05d664c9de..f9f56b9002 100644
--- a/bittensor/__main__.py
+++ b/bittensor/__main__.py
@@ -15,7 +15,24 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+import os
+import subprocess
+import sys
+
from bittensor import __version__
if __name__ == "__main__":
- print(f"Bittensor SDK version: {__version__}")
+ if len(sys.argv) > 1 and sys.argv[1] == "certifi":
+ # Resolve the path to certifi.sh
+ certifi_script = os.path.join(os.path.dirname(__file__), "utils", "certifi.sh")
+ if not os.path.exists(certifi_script):
+ print(f"Error: certifi.sh not found at {certifi_script}")
+ sys.exit(1)
+
+ # Ensure the script is executable
+ os.chmod(certifi_script, 0o755)
+
+ # Run the script
+ subprocess.run([certifi_script], check=True)
+ else:
+ print(f"Bittensor SDK version: {__version__}")
diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py
index a26a02638c..6c17cc87b0 100644
--- a/bittensor/core/subtensor.py
+++ b/bittensor/core/subtensor.py
@@ -238,6 +238,14 @@ def _get_substrate(self):
f"Could not connect to {self.network} network with {self.chain_endpoint} chain endpoint.",
)
raise ConnectionRefusedError(error.args)
+ except ssl.SSLError as e:
+ logging.critical(
+ "SSL error occurred. To resolve this issue, run the following command in your terminal:"
+ )
+ logging.critical("[blue]sudo python -m bittensor certifi[/blue]")
+ raise RuntimeError(
+ "SSL configuration issue, please follow the instructions above."
+ ) from e
@staticmethod
def config() -> "Config":
diff --git a/bittensor/utils/certifi.sh b/bittensor/utils/certifi.sh
new file mode 100755
index 0000000000..9dd4a68fe3
--- /dev/null
+++ b/bittensor/utils/certifi.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Locate Python 3
+PYTHON=$(command -v python3)
+if [ -z "$PYTHON" ]; then
+ echo "Error: Python 3 is not installed or not found in PATH."
+ exit 1
+fi
+
+echo "Using Python: $PYTHON"
+
+echo " -- Upgrading the certifi package"
+$PYTHON -m pip install --upgrade certifi
+
+echo " -- Fetching the path to the certifi certificate bundle"
+CERTIFI_CAFILE=$($PYTHON -c "import certifi; print(certifi.where())")
+
+echo " -- Resolving OpenSSL directory and certificate file path"
+OPENSSL_DIR=$($PYTHON -c "import ssl; print(ssl.get_default_verify_paths().openssl_cafile.rsplit('/', 1)[0])")
+OPENSSL_CAFILE=$($PYTHON -c "import ssl; print(ssl.get_default_verify_paths().openssl_cafile.rsplit('/', 1)[-1])")
+
+echo " -- Navigating to the OpenSSL directory"
+cd "$OPENSSL_DIR" || { echo "Failed to navigate to $OPENSSL_DIR"; exit 1; }
+
+echo " -- Removing any existing certificate file or symlink"
+rm -f "$OPENSSL_CAFILE"
+
+echo " -- Creating a symlink to the certifi certificate bundle"
+ln -s "$CERTIFI_CAFILE" "$OPENSSL_CAFILE"
+
+echo " -- Setting appropriate file permissions"
+chmod 775 "$OPENSSL_CAFILE"
+
+echo " -- Update complete"
diff --git a/setup.py b/setup.py
index 73068b8315..99d5891e12 100644
--- a/setup.py
+++ b/setup.py
@@ -69,6 +69,9 @@ def read_requirements(path):
author="bittensor.com",
packages=find_packages(exclude=["tests", "tests.*"]),
include_package_data=True,
+ package_data={
+ "bittensor": ["utils/certifi.sh"],
+ },
author_email="",
license="MIT",
python_requires=">=3.9",