diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index 919beab3..87222f54 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -55,7 +55,6 @@ def __init__(self, rpc_error): class RawProxy(object): - # FIXME: need a CChainParams rather than hard-coded service_port def __init__(self, service_url=None, service_port=None, btc_conf_file=None, @@ -79,7 +78,8 @@ def __init__(self, service_url=None, # Extract contents of bitcoin.conf to build service_url with open(btc_conf_file, 'r') as fd: - conf = {} + # Bitcoin Core accepts empty rpcuser, not specified in btc_conf_file + conf = {'rpcuser': ""} for line in fd.readlines(): if '#' in line: line = line[:line.index('#')] @@ -100,6 +100,9 @@ def __init__(self, service_url=None, else: raise ValueError('Unknown rpcssl value %r' % conf['rpcssl']) + if 'rpcpassword' not in conf: + raise ValueError('The value of rpcpassword not specified in the configuration file: %s' % btc_conf_file) + service_url = ('%s://%s:%s@localhost:%d' % ('https' if conf['rpcssl'] else 'http', conf['rpcuser'], conf['rpcpassword'], @@ -108,7 +111,10 @@ def __init__(self, service_url=None, self.__service_url = service_url self.__url = urlparse.urlparse(service_url) if self.__url.port is None: - port = 80 + if self.__url.scheme == 'https': + port = httplib.HTTPS_PORT + else: + port = httplib.HTTP_PORT else: port = self.__url.port self.__id_count = 0