<p>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 <code>Broken pipe</code> errors.</p>

CC BY-SA 4.0
2019-07-21T09:00:18.200Z
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
CC BY-SA 4.0
2019-07-21T16:12:21.373Z
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
CC BY-SA 4.0
2019-07-22T09:35:06.357Z
Yes, your are right. Or I can reconnect the server each time when I send a query.
Jun Fang
CC BY-SA 4.0
2019-07-21T03:58:48.710Z
2019-07-21T03:58:48.710Z
Ava Chow
<p>I am using <a href="https://github.com/jgarzik/python-bitcoinrpc" rel="nofollow noreferrer">https://github.com/jgarzik/python-bitcoinrpc</a> to access the bitcoin core rpc. I have found a very strange re-connection problem.</p>

<pre><code>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))
</code></pre>

<p>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:</p>

<pre><code>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
</code></pre>

<p>if I reconnect the server again by running line1, then line2 runs well.</p>

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

<bitcoind><json-rpc><client><development><python>
Strange re-connection problem with python-bitcoinrpc
Jun Fang
# Strange re-connection problem with python-bitcoinrpc

(Asked by: username_0 on 2019-07-21)

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 "", line 1, in 
  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.

**Tags:** bitcoind, json-rpc, client, development, python


---

## 1 answers

### Answer by username_1 on 2019-07-21. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: 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.  
> **username_0**: Yes, your are right. Or I can reconnect the server each time when I send a query.  

---

