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,)):