0
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 "<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.
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 – 2019-07-21T09:00:18.200
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=1200in your bitcoin.conf file and restarting Bitcoin Core. – Andrew Chow – 2019-07-21T16:12:21.373Yes, your are right. Or I can reconnect the server each time when I send a query. – Jun Fang – 2019-07-22T09:35:06.357