Browse Source

Merge #118: Reconnect automatically when bitcoind connection times out

0a55558 Reconnect automatically when bitcoind connection times out (James Hilliard)
master
AdamISZ 8 years ago
parent
commit
b8d47ec725
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 56
      jmclient/jmclient/jsonrpc.py

56
jmclient/jmclient/jsonrpc.py

@ -74,31 +74,37 @@ class JsonRpc(object):
body = json.dumps(obj)
try:
self.conn.request("POST", "", body, headers)
response = self.conn.getresponse()
if response.status == 401:
self.conn.close()
raise JsonRpcConnectionError(
"authentication for JSON-RPC failed")
# All of the codes below are 'fine' from a JSON-RPC point of view.
if response.status not in [200, 404, 500]:
self.conn.close()
raise JsonRpcConnectionError("unknown error in JSON-RPC")
data = response.read()
return json.loads(data)
except JsonRpcConnectionError as exc:
raise exc
except httplib.BadStatusLine:
return "CONNFAILURE"
except Exception as exc:
raise JsonRpcConnectionError("JSON-RPC connection failed. Err:" +
repr(exc))
while True:
try:
self.conn.request("POST", "", body, headers)
response = self.conn.getresponse()
if response.status == 401:
self.conn.close()
raise JsonRpcConnectionError(
"authentication for JSON-RPC failed")
# All of the codes below are 'fine' from a JSON-RPC point of view.
if response.status not in [200, 404, 500]:
self.conn.close()
raise JsonRpcConnectionError("unknown error in JSON-RPC")
data = response.read()
return json.loads(data)
except JsonRpcConnectionError as exc:
raise exc
except httplib.BadStatusLine:
return "CONNFAILURE"
except Exception as exc:
if str(exc) == "Connection reset by peer":
self.conn.connect()
continue
else:
raise JsonRpcConnectionError("JSON-RPC connection failed. Err:" +
repr(exc))
break
def call(self, method, params):
"""

Loading…
Cancel
Save