Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion bittensor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}")
8 changes: 8 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ def _get_substrate(self):
f"<red>Could not connect to</red> <blue>{self.network}</blue> <red>network with</red> <blue>{self.chain_endpoint}</blue> <red>chain endpoint.</red>",
)
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":
Expand Down
34 changes: 34 additions & 0 deletions bittensor/utils/certifi.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down