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:%firstname.lastname@example.org: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 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.