<p>I found the solution. After doing changes in bitcoin config file, I just reduce the range of records to be inserted. RPC server cannot handle loads of data at one time. Otherwise, server down problem occurs and connection failed. Max 100 records get inserted at a time or less than that.
And one more thing, keep restarting bitcoind RPC server by stop and start commands given below:</p>

<pre><code>sudo killall bitcoind
bitcoind -daemon -rpcuser=xxx -rpcpassword=xxx -txindex -rpcallowip=youripaddress
</code></pre>

CC BY-SA 4.0
2020-01-16T09:19:39.760Z
Just in case this is still relevant, I used to have broken pipe errors while using the bitcoinrpc from PyPi, stop getting them after switching to the modified version in Bitcoin Core https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/authproxy.py
sr_gi
CC BY-SA 4.0
2018-12-20T07:55:17.270Z
2018-12-20T09:29:25.157Z
2018-12-20T09:29:25.157Z
Varsh
<p>I am trying to insert bitcoin transactions into MongoDB using python3. Below is my code :</p>

<pre><code>import pymongo
import sys
import json
import time
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

rpc_connection = AuthServiceProxy("http://xxx:xxx@ipaddress:port")

def getTransaction():
    addresses = []
    txa = []
    commands = [ [ "getblockhash", height] for height in range(400000,550000) ]
    #print(commands)

    block_hashes = rpc_connection.batch_(commands)
    blocks = rpc_connection.batch_([ [ "getblock", h ] for h in block_hashes ])
    print(blocks)
    for txpre in blocks:
        #print(txpre)
        for txs in txpre["tx"]:
            txa.append(txs)
    trans = conTransaction(txa)
    return trans
</code></pre>

<p>I am getting following error :     </p>

<pre><code>Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "Test06.py", line 252, in getBTCTransaction
    block_hashes = rpc_connection.batch_(commands)
  File "/home/administrator/.local/lib/python3.6/site-packages/bitcoinrpc/authproxy.py", line 165, in batch_
    'Content-type': 'application/json'})
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
</code></pre>

<p>I checked bitcoind  rpc connection,its connected.<br>
   <code>block_hashes = rpc_connection.batch_(commands)</code> this code line is giving error. Can somebody tell me what's wrong?
Working on a remote server.</p>

CC BY-SA 4.0
2018-12-18T11:14:28.603Z
did you obfuscate "http://xxx:xxx@ipaddress:port" for this question or do you have it like this in your code? in that case it would be clear why can't connect to it. Did you also check bitcoind to have the http-rpc interface open?
Rene Pickhardt
CC BY-SA 4.0
2018-12-18T11:19:47.067Z
No, I have my IP address, port, user password in my code. I obfuscate it just for this question. Can you pleasse tell me how to check bitcoind to have the http-rpc interface open? I am new to bitcoind
Varsh
CC BY-SA 4.0
2018-12-18T11:21:11.860Z
try `wget http://xxx:xxx@ipaddress:port` or `curl` you could even check with a networking tool if you really have a port open. also check your bitcoin.conf (c.f.: https://en.bitcoin.it/wiki/Running_Bitcoin you need to uncomment the lines for the RPC)
Rene Pickhardt
CC BY-SA 4.0
2018-12-18T11:24:47.057Z
I tried this "wget http://xxx:xxx@ipaddress:port". Its giving response 200 OK.
Varsh
CC BY-SA 4.0
2018-12-18T12:44:18.013Z
Given list rpc lines are uncommented and changed. Please check.        server=1                                                                                                               
rpcuser=xxx
rpcpassword=xxx                                                                                                 
rpcclienttimeout=60                                          
rpcallowip=remote_ipaddress_on_which_working/port                      
rpcport=port                                                 rpcconnect=remote_ipaddress_on_which_working
Varsh
CC BY-SA 4.0
2018-12-18T14:10:40.193Z
if you get `200 OK` via wget we can know that your bitcoin node really is running as expected. so the problem seems to be from your client lib. from the error log it seems that you are making the http request while doing multithreading. I don't see something like this in your code example but could it be that you are closing the TCP socket before bitcoin is able to give you an answer? have you tried doing a JSON http request yourself in pythong without this client lib? also I am wondering that the lib is located in /home/adminstrator/... did you install it with sudo?
Rene Pickhardt
CC BY-SA 4.0
2018-12-19T05:48:00.820Z
After doing changes in bitcoin.conf now I am getting socket.timeout: timed out error
Varsh
<bitcoind><python>
Bitcoin RPC connection
Varsh
# Bitcoin RPC connection

(Asked by: username_0 on 2018-12-18)

I am trying to insert bitcoin transactions into MongoDB using python3. Below is my code :
import pymongo
import sys
import json
import time
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

rpc_connection = AuthServiceProxy("http://xxx:xxx@ipaddress:port")

def getTransaction():
    addresses = []
    txa = []
    commands = [ [ "getblockhash", height] for height in range(400000,550000) ]
    #print(commands)

    block_hashes = rpc_connection.batch_(commands)
    blocks = rpc_connection.batch_([ [ "getblock", h ] for h in block_hashes ])
    print(blocks)
    for txpre in blocks:
        #print(txpre)
        for txs in txpre["tx"]:
            txa.append(txs)
    trans = conTransaction(txa)
    return trans

I am getting following error :     
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "Test06.py", line 252, in getBTCTransaction
    block_hashes = rpc_connection.batch_(commands)
  File "/home/administrator/.local/lib/python3.6/site-packages/bitcoinrpc/authproxy.py", line 165, in batch_
    'Content-type': 'application/json'})
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

I checked bitcoind  rpc connection,its connected.
block_hashes = rpc_connection.batch_(commands) this code line is giving error. Can somebody tell me what's wrong?
Working on a remote server.

**Tags:** bitcoind, python

> **Comments:**
> **username_1**: did you obfuscate "http://xxx:xxx@ipaddress:port" for this question or do you have it like this in your code? in that case it would be clear why can't connect to it. Did you also check bitcoind to have the http-rpc interface open?  
> **username_0**: No, I have my IP address, port, user password in my code. I obfuscate it just for this question. Can you pleasse tell me how to check bitcoind to have the http-rpc interface open? I am new to bitcoind  
> **username_1**: try `wget http://xxx:xxx@ipaddress:port` or `curl` you could even check with a networking tool if you really have a port open. also check your bitcoin.conf (c.f.: https://en.bitcoin.it/wiki/Running_Bitcoin you need to uncomment the lines for the RPC)  
> **username_0**: I tried this "wget http://xxx:xxx@ipaddress:port". Its giving response 200 OK.  
> **username_0**: Given list rpc lines are uncommented and changed. Please check.        server=1                                                                                                                rpcuser=xxx rpcpassword=xxx                                                                                                  rpcclienttimeout=60                                           rpcallowip=remote_ipaddress_on_which_working/port                       rpcport=port                                                 rpcconnect=remote_ipaddress_on_which_working  
> **username_1**: if you get `200 OK` via wget we can know that your bitcoin node really is running as expected. so the problem seems to be from your client lib. from the error log it seems that you are making the http request while doing multithreading. I don't see something like this in your code example but could it be that you are closing the TCP socket before bitcoin is able to give you an answer? have you tried doing a JSON http request yourself in pythong without this client lib? also I am wondering that the lib is located in /home/adminstrator/... did you install it with sudo?  
> **username_0**: After doing changes in bitcoin.conf now I am getting socket.timeout: timed out error  

---

## 1 answers

### Answer by username_0 on 2018-12-20. Score: 0 | Accepted answer

I found the solution. After doing changes in bitcoin config file, I just reduce the range of records to be inserted. RPC server cannot handle loads of data at one time. Otherwise, server down problem occurs and connection failed. Max 100 records get inserted at a time or less than that.
And one more thing, keep restarting bitcoind RPC server by stop and start commands given below:
sudo killall bitcoind
bitcoind -daemon -rpcuser=xxx -rpcpassword=xxx -txindex -rpcallowip=youripaddress

> **Comments:**
> **username_2**: Just in case this is still relevant, I used to have broken pipe errors while using the bitcoinrpc from PyPi, stop getting them after switching to the modified version in Bitcoin Core https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/authproxy.py  

---

