jgarzik / python-bitcoinrpc

Python interface to bitcoin's JSON-RPC API
GNU Lesser General Public License v2.1
644 stars 304 forks source link

BrokenPipeError: [Errno 32] Broken pipe #78

Open toxicologist opened 6 years ago

toxicologist commented 6 years ago

Trying to create a raw transaction on the testnet gives the following error:

  File "<pyshell#11>", line 1, in <module>
    con.createrawtransaction([{"txid":"a8fd2dacb674cec804e1cd861c9310d999d6d149fd17d5e44034ed1207860f60","vout":0}], {"myJXY5WznWSLqSoghhieCXfykkZnCz9P1U":1.79})
  File "/usr/local/lib/python3.5/dist-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
>>> 
dlypka59 commented 5 years ago

I believe the Broken pipe happens if you are typing commands from a python console and you wait too long between requests. I had this error but resolved it by not lingering between requests and also by adding the timeout arg as suggested in the Readme.rst: Socket timeouts under heavy load Pass the timeout argument to prevent "socket timed out" exceptions: rpc_connection = AuthServiceProxy( "http://%s:%s@%s:%s"%(rpc_user, rpc_password, rpc_host, rpc_port), timeout=120)

If the Broken pipe error still occurs then perhaps some sort of Keep Alive (do nothing) request should be sent at rapid intervals to keep the Pipe from closing. Or else trap the Broken pipe exception and make a new connection.