python-bitcoinlib icon indicating copy to clipboard operation
python-bitcoinlib copied to clipboard

refactor BaseProxy __init__ method

Open sorce opened this issue 8 years ago • 2 comments
trafficstars

This pull request refactors some of the BaseProxy __init__ methods code to better support the reading in of RPC credentials.

Currently the code will only attempt to read in a cookie file if a configuration file exists and a valid rpcpassword variable is not found in it. This change will fail silently if the configuration file does not exist or is unable to be read (permission issue, etc.), continuing on to try to read a cookie file. if we are unable to find valid credentials in a configuration file and also not able to read a cookie file then we fail and alert the user.

This also fixes a bug introduced in #144 where only passing in a service_url to one of the Proxy classes resulted in an UnboundLocalError like:

Traceback (most recent call last):
  ...
    rpc = bitcoin.rpc.BaseProxy(service_url=url)
  File "/home/sorce/Coding/venvs/test/lib/python3.6/site-packages/bitcoin/rpc.py", line 189, in __init__
    authpair = authpair.encode('utf8')
UnboundLocalError: local variable 'authpair' referenced before assignment

authpair is now checked prior to making the connection and if it is None we assign the parsed username/password from service_url

sorce avatar Aug 28 '17 05:08 sorce

Well, this solves the authpair bug at least.

kanzure avatar Sep 18 '17 00:09 kanzure

@petertodd

Please take a look at this PR.

RPC interface in version 0.8.0 can't be used due to UnboundLocalError in __init__ method.

xuhcc avatar Oct 04 '17 14:10 xuhcc