I am using https://github.com/jgarzik/python-bitcoinrpc to access the bitcoin core rpc. I have found a very strange re-connection problem.

from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

# rpc_user and rpc_password are set in the bitcoin.conf file
1. rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8332"%(rpc_user, rpc_password))
2. best_block_hash = rpc_connection.getbestblockhash()
3. print(rpc_connection.getblock(best_block_hash))

The above code runs well in the python interactive window. However, after a while (for instance 10s), when I run the line2 again, it crashs with following info:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fangjun/.local/lib/python3.5/site-packages/bitcoinrpc/authproxy.py", line 136, in __call__
    'Content-type': 'application/json'})
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
  File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
  File "/usr/lib/python3.5/http/client.py", line 908, in send
BrokenPipeError: [Errno 32] Broken pipe

if I reconnect the server again by running line1, then line2 runs well.

It seems I need to run line1 from time to time, but it doesn't make sense. Can some tell me the reason? Thanks.

1 Answer 1


Both the RPC client and the RPC server have timeouts, if no request or response has been received for X seconds, they will close the connection. By default the timeout is 30 seconds. I believe you are running into the timeout since you wait a while before trying to send another command. By that point, one end has timed out and thus the connection is closed resulting in Broken pipe errors.

  • Thanks for your reply. I set the timeout=1200, but it doesn't work for 1200s. I found when I run line1 and line2, then after 60s, I run line2 again, it crashes, even I set the timeout very large.
    – Jun Fang
    Commented Jul 21, 2019 at 9:00
  • The server has it's own timeout, so even if you increase the timeout on your client, the server will still timeout after 30 seconds. You can change that setting rpcservertimeout=1200 in your bitcoin.conf file and restarting Bitcoin Core.
    – Ava Chow
    Commented Jul 21, 2019 at 16:12
  • Yes, your are right. Or I can reconnect the server each time when I send a query.
    – Jun Fang
    Commented Jul 22, 2019 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.