<p>Change the timeout inside the file bitcoin.conf or when you start the bitcoind,</p>

<p>This is an example</p>

<pre><code>##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##
# On client-side, you add the normal user/password pair to send commands:
rpcuser=alice
rpcpassword=bob
rpcclienttimeout=200
</code></pre>

<p>or you can run the bitcoind with this command <code>bitcoind -rpcuser=alice -rpcpassword=bob -rpcclienttimeout=200</code></p>

<p>Or you can change the setting lib to the code, try this example</p>

<pre><code>from bitcoin.rpc import RawProxy

# Create a connection to local Bitcoin Core node
p = RawProxy(None, None, None, 120)

# Run the getblockchaininfo command, store the resulting data in info
info = p.getblockchaininfo()

# Retrieve the 'blocks' element from the info
print(info['blocks'])
</code></pre>

CC BY-SA 4.0
2019-08-29T10:27:19.687Z
Unfortunately, this does not work. I think it is because there is another timeout happening before, the one which is defined for the HTTP inside the library.
bomben
CC BY-SA 4.0
2019-08-29T10:59:58.460Z
update the answer
vincenzopalazzo
CC BY-SA 4.0
2019-08-29T09:42:18.210Z
2019-08-29T10:59:48.580Z
2019-08-29T10:59:48.580Z
vincenzopalazzo
<p>I had to change the timeout variable that is used inside the method of the library by giving a value to it when calling the method.  </p>

CC BY-SA 4.0
2019-09-20T13:49:21.740Z
2019-09-20T13:49:21.740Z
bomben
<p>I am using a small script and get a timeout from python. This is my script:</p>

<pre><code>import bitcoin
import bitcoin.rpc
from bitcoin.rpc import RawProxy
p = RawProxy()
hash = '0000000000000001b6b9a13b095e96db41c4a928b97ef2d944a9b31b2cc7bdc4'
infoblock = p.getblock(hash)
print(infoblock['difficulty'])
</code></pre>

<p>This is my error:</p>

<pre><code>bitcoin@raspberrypi ~/.bitcoin/BuchSkripte $ python3 49_rpc_example.py
Traceback (most recent call last):
  File "49_rpc_example.py", line 11, in &lt;module&gt;
    infoblock = p.getblock(hash)
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 306, in &lt;lambda&gt;
    f = lambda *args: self._call(name, *args)
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 236, in _call
    response = self._get_response()
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 261, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.5/socket.py", line 576, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out
</code></pre>

<p>When using the same method <code>getblock</code> via <code>bitcoin-cli</code> it takes 120 seconds to finish on my Raspberry. If the timeout is related to this duration, can I increase it in the script?</p>

<p>I <a href="https://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method/53560146#53560146">read</a> that the socket timeout can be set but I wonder if I can do this if I use a library for the connection. </p>

<python><python-bitcoinlib>
Why do I have a socket.timeout with python-bitcoinlib?
bomben
# Why do I have a socket.timeout with python-bitcoinlib?

(Asked by: username_0 on 2019-08-29)

I am using a small script and get a timeout from python. This is my script:

```
import bitcoin
import bitcoin.rpc
from bitcoin.rpc import RawProxy
p = RawProxy()
hash = '0000000000000001b6b9a13b095e96db41c4a928b97ef2d944a9b31b2cc7bdc4'
infoblock = p.getblock(hash)
print(infoblock['difficulty'])

```

This is my error:

```
bitcoin@raspberrypi ~/.bitcoin/BuchSkripte $ python3 49_rpc_example.py
Traceback (most recent call last):
  File "49_rpc_example.py", line 11, in <module>
    infoblock = p.getblock(hash)
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 306, in <lambda>
    f = lambda *args: self._call(name, *args)
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 236, in _call
    response = self._get_response()
  File "/usr/local/lib/python3.5/dist-packages/bitcoin/rpc.py", line 261, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1198, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.5/socket.py", line 576, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

```

When using the same method `getblock` via `bitcoin-cli` it takes 120 seconds to finish on my Raspberry. If the timeout is related to this duration, can I increase it in the script?

I [read](https://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method/53560146#53560146) that the socket timeout can be set but I wonder if I can do this if I use a library for the connection.

**Tags:** python, python-bitcoinlib


---

## 2 answers

### Answer by username_1 on 2019-08-29. Score: 2

Change the timeout inside the file bitcoin.conf or when you start the bitcoind,

This is an example

```
##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##
# On client-side, you add the normal user/password pair to send commands:
rpcuser=alice
rpcpassword=bob
rpcclienttimeout=200

```

or you can run the bitcoind with this command `bitcoind -rpcuser=alice -rpcpassword=bob -rpcclienttimeout=200`

Or you can change the setting lib to the code, try this example

```
from bitcoin.rpc import RawProxy

# Create a connection to local Bitcoin Core node
p = RawProxy(None, None, None, 120)

# Run the getblockchaininfo command, store the resulting data in info
info = p.getblockchaininfo()

# Retrieve the 'blocks' element from the info
print(info['blocks'])

```

> **Comments:**
> **username_0**: Unfortunately, this does not work. I think it is because there is another timeout happening before, the one which is defined for the HTTP inside the library.  
> **username_1**: update the answer  

---

### Answer by username_0 on 2019-09-20. Score: 0

I had to change the timeout variable that is used inside the method of the library by giving a value to it when calling the method.


---

