Strange re-connection problem with python-bitcoinrpc 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:%s@127.0.0.1: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 "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
    self.send(message_body)
  File "/usr/lib/python3.5/http/client.py", line 908, in send
    self.sock.sendall(data)
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.
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.