55# --------------------------------------------------------------------
66
77from collections import namedtuple
8+ from urllib .parse import urlparse
89
910from eth_utils import to_dict
1011from requests import Session
1314)
1415
1516from tronapi .providers .base import BaseProvider
16- from . .exceptions import HTTP_EXCEPTIONS , TransportError
17+ from tronapi .exceptions import HTTP_EXCEPTIONS , TransportError
1718
19+ HTTP_SCHEMES = {'http' , 'https' }
1820HttpResponse = namedtuple ('HttpResponse' , ('status_code' , 'headers' , 'data' ))
1921
2022
@@ -32,6 +34,18 @@ def __init__(self, node_url, request_kwargs=None):
3234 """
3335
3436 self .node_url = node_url .rstrip ('/' )
37+ uri = urlparse (node_url )
38+
39+ # This condition checks the node that will connect
40+ # to work with methods.
41+ if uri .scheme not in HTTP_SCHEMES :
42+ raise NotImplementedError (
43+ 'TronAPI does not know how to connect to scheme %r in %r' % (
44+ uri .scheme ,
45+ self .node_url ,
46+ )
47+ )
48+
3549 self ._request_kwargs = request_kwargs or {}
3650 self .session = Session ()
3751
@@ -67,11 +81,14 @@ def request(self, path, json=None, params=None, method=None):
6781 return response .data
6882
6983 def is_connected (self ) -> bool :
70- """Checking the connection from the connected node
84+ """Connection check
7185
72- Returns:
73- bool: True if successful, False otherwise .
86+ This method sends a test request to the connected node
87+ to determine its health .
7488
89+ Returns:
90+ bool: True if successful,
91+ False otherwise.
7592 """
7693 response = self .request (path = self .status_page , method = 'get' )
7794 if 'blockID' in response or response == 'OK' :
0 commit comments