Skip to content

Commit d010795

Browse files
committed
fix api_status bug
1 parent 16d8327 commit d010795

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

src/apiClient.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
from misc import getCallerName, getFunctionName, printException, printDbg
77

88
api_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

2211
def 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

src/tabRewards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def load_utxos_thread(self, ctrl):
192192

193193
api_status = self.caller.apiClient.getStatus()
194194
if api_status != 200:
195-
printDbg("Wrong response from API client. Status: %s" % status)
195+
printDbg("Wrong response from API client. Status: %s" % api_status)
196196
return
197197

198198
self.apiConnected = True

src/version.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"number": "0.3.99",
3-
"tag": "l",
4-
"comments": ["Governance DB"]
3+
"tag": "m",
4+
"comments": ["api_status bug"]
55
}

src/watchdogThreads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def run(self):
3434
# first time we get connection reload UTXOs and Proposals
3535
if not self.control_tab.t_rewards.utxoLoaded:
3636
self.control_tab.t_rewards.load_utxos_thread(None)
37+
3738
if not self.control_tab.t_governance.proposalsLoaded:
3839
self.control_tab.t_governance.loadProposals_thread(None)
3940

0 commit comments

Comments
 (0)