From 6a6b6f9354df2f84e9aac3ecde51f611415b4172 Mon Sep 17 00:00:00 2001 From: asdfds Date: Fri, 19 Jul 2019 20:04:26 +0200 Subject: [PATCH] Request exceptions catched to prevent entering in a broken connection state --- bitcoinrpc/authproxy.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bitcoinrpc/authproxy.py b/bitcoinrpc/authproxy.py index abebe4b..cc72553 100644 --- a/bitcoinrpc/authproxy.py +++ b/bitcoinrpc/authproxy.py @@ -130,11 +130,15 @@ def __call__(self, *args): 'method': self.__service_name, 'params': args, 'id': AuthServiceProxy.__id_count}, default=EncodeDecimal) - self.__conn.request('POST', self.__url.path, postdata, - {'Host': self.__url.hostname, - 'User-Agent': USER_AGENT, - 'Authorization': self.__auth_header, - 'Content-type': 'application/json'}) + try: + self.__conn.request('POST', self.__url.path, postdata, + {'Host': self.__url.hostname, + 'User-Agent': USER_AGENT, + 'Authorization': self.__auth_header, + 'Content-type': 'application/json'}) + except Exception as e: + self.__conn.close() + raise e self.__conn.sock.settimeout(self.__timeout) response = self._get_response() @@ -159,11 +163,15 @@ def batch_(self, rpc_calls): postdata = json.dumps(batch_data, default=EncodeDecimal) log.debug("--> "+postdata) - self.__conn.request('POST', self.__url.path, postdata, - {'Host': self.__url.hostname, - 'User-Agent': USER_AGENT, - 'Authorization': self.__auth_header, - 'Content-type': 'application/json'}) + try: + self.__conn.request('POST', self.__url.path, postdata, + {'Host': self.__url.hostname, + 'User-Agent': USER_AGENT, + 'Authorization': self.__auth_header, + 'Content-type': 'application/json'}) + except Exception as e: + self.__conn.close() + raise e results = [] responses = self._get_response() if isinstance(responses, (dict,)):