Skip to content

Commit ea73e3f

Browse files
author
Marek Miller
committed
Do not assume that bitcoin.conf file specifies rpcuser
and raise an exception if rpcpassword is not specified. Comment: You can make RPC calls to bitcoind when bitcoin.conf specifies just rpcpassword and leaves user name empty. The class bitcoin.rpc.RawProxy creates keys of the internal dictionary: conf = {}, based on the entries in the configuration file. Then assumes that the rpcuser key exists and uses it to create service_url. This results in an error when bitcoin.conf contains only rcppassword field and the following code is executed: > proxy = bitcoin.rpc.RawProxy()
1 parent 3d796d8 commit ea73e3f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

bitcoin/rpc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def __init__(self, service_url=None,
7878

7979
# Extract contents of bitcoin.conf to build service_url
8080
with open(btc_conf_file, 'r') as fd:
81-
conf = {}
81+
# Bitcoin Core accepts empty rpcuser, not specified in btc_conf_file
82+
conf = {'rpcuser': ""}
8283
for line in fd.readlines():
8384
if '#' in line:
8485
line = line[:line.index('#')]
@@ -99,6 +100,9 @@ def __init__(self, service_url=None,
99100
else:
100101
raise ValueError('Unknown rpcssl value %r' % conf['rpcssl'])
101102

103+
if 'rpcpassword' not in conf:
104+
raise ValueError('The value of rpcpassword not specified in the configuration file: %s' % btc_conf_file)
105+
102106
service_url = ('%s://%s:%s@localhost:%d' %
103107
('https' if conf['rpcssl'] else 'http',
104108
conf['rpcuser'], conf['rpcpassword'],

0 commit comments

Comments
 (0)