66from misc import getCallerName , getFunctionName , printException , printDbg
77
88api_keys = ["b62b40b5091e" , "f1d66708a077" , "ed85c85c0126" , "ccc60d06f737" ]
9-
10- class DisconnectedException (Exception ):
11- def __init__ (self , message , apiClient ):
12- # Call the base class constructor
13- super ().__init__ (message )
14- # clear client
15- try :
16- apiClient .client .close ()
17- apiClient .client = requests .session ()
18- except Exception :
19- pass
209
2110
2211def process_api_exceptions (func ):
@@ -25,14 +14,11 @@ def process_api_exceptions_int(*args, **kwargs):
2514 apiClient = args [0 ]
2615 try :
2716 return func (* args , ** kwargs )
28-
29- except DisconnectedException as e :
30- raise e
31-
17+
3218 except Exception as e :
3319 message = "API Client exception"
3420 printException (getCallerName (True ), getFunctionName (True ), message , str (e ))
35- raise DisconnectedException ( message , apiClient )
21+ return None
3622
3723 return process_api_exceptions_int
3824
@@ -44,7 +30,6 @@ def __init__(self):
4430 self .url = "http://chainz.cryptoid.info/pivx/api.dws"
4531 self .parameters = {}
4632
47-
4833
4934 def checkResponse (self , parameters ):
5035 key = choice (api_keys )
@@ -53,9 +38,7 @@ def checkResponse(self, parameters):
5338 if resp .status_code == 200 :
5439 data = resp .json ()
5540 return data
56- else :
57- raise DisconnectedException ("Wrong Response" , self )
58- return None
41+ return None
5942
6043
6144
@@ -76,14 +59,16 @@ def getBalance(self, address):
7659 return self .checkResponse (self .parameters )
7760
7861
79-
80- @process_api_exceptions
8162 def getStatus (self ):
8263 status_code = 0
8364 self .parameters = {}
8465 self .parameters ['q' ] = 'getblockcount'
85- resp = requests .get (self .url , self .parameters )
86- status_code = resp .status_code
66+ try :
67+ resp = requests .get (self .url , self .parameters )
68+ status_code = resp .status_code
69+ except Exception as e :
70+ printException (getCallerName (True ), getFunctionName (True ), "API ERR" , str (e ))
71+
8772 return status_code
8873
8974
0 commit comments