Skip to content

Commit ccca15b

Browse files
committed
Fix spurious AttributeError in bitcoin.rpc.Proxy()
Previously if the proxy connection couldn't be created for some reason, when the proxy object was deleted a spurious AttributeError could be raised due to a missing __conn attribute. Now only the actual exception will be raised.
1 parent 5e150ac commit ccca15b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bitcoin/rpc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def __init__(self,
8383
btc_conf_file=None,
8484
timeout=DEFAULT_HTTP_TIMEOUT):
8585

86+
# Create a dummy connection early on so if __init__() fails prior to
87+
# __conn being created __del__() can detect the condition and handle it
88+
# correctly.
89+
self.__conn = None
90+
8691
if service_url is None:
8792
# Figure out the path to the bitcoin.conf file
8893
if btc_conf_file is None:
@@ -181,7 +186,8 @@ def _get_response(self):
181186
parse_float=decimal.Decimal)
182187

183188
def __del__(self):
184-
self.__conn.close()
189+
if self.__conn is not None:
190+
self.__conn.close()
185191

186192

187193
class RawProxy(BaseProxy):

release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Breaking API changes:
99
* The 'cooked' CScript iterator now returns OP_0 for the empty binary string
1010
rather than b''
1111

12+
Bugfixes:
13+
14+
* Fixed a spurious AttributeError when bitcoin.rpc.Proxy() fails.
15+
1216

1317
v0.6.1
1418
======

0 commit comments

Comments
 (0)