I am new to python-bitcoinrpc(also new to VM Linux actually) and I want to use the blockchain parser from alecalve to get ordered blocks. I used Windows to download the blockchain data into an external hard drive as well as bitcoin.conf but then I found that this parser could only be used on Linux, so I downloaded Bitcoin Core again on Linux and run

./bitcoin-qt -datadir=/media/myharddrive/Bitcoin -conf=/media/myharddrive/Bitcoin/bitcoin.conf

to avoid re-downloading the data.

However, it seems I cannot connect to rpc because the simple code

rpc_connection = AuthServiceProxy("http://%s:%s@"%('rpcuser', 'myrpcpassword'))

best_block_hash = rpc_connection.getbestblockhash()

returns error like this

Traceback (most recent call last):
  File "process1.py", line 129, in <module>
  File "process1.py", line 62, in parser
    prevtxhex = rpc_connection.getrawtransaction(prevtxidhash,0)
  File "/home/lylian/.local/lib/python3.8/site-packages/bitcoinrpc/authproxy.py", line 132, in __call__
    self.__conn.request('POST', self.__url.path, postdata,
  File "/usr/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1225, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1004, in _send_output
  File "/usr/lib/python3.8/http/client.py", line 944, in send
  File "/usr/lib/python3.8/http/client.py", line 915, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
ConnectionRefusedError: [Errno 111] Connection refused

I wonder if it's because my code cannot find bitcoin.conf(I put it both in the default location and my hard drive) or there is something wrong with my settings.


Thanks very much!!

  • can you upload also your bitcoin.conf? – vincenzopalazzo Apr 30 '20 at 17:59
  • already did, it's just simple... – Lylian May 1 '20 at 2:05
  • add rpcuser=sandbox , rpcpassword=sendbox, rpcport=8332 bind= and you can use this python script to test the node with python – vincenzopalazzo May 1 '20 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.