<p>Thanks in advance.
If I call getblockchaininfo through bitcoin-cli it just works. It might take a while but it works all the time.
If I call it from within a Python Script</p>

<pre><code>from bitcoin.rpc import RawProxy
...
# create a connection to local Bitcoin Core node
p = RawProxy()
...
info = p.getblockchaininfo()
...
</code></pre>

<p>then 8 out of 10 times it breaks...</p>

<pre><code>~$python .bitcoin/blockheigh.py
Traceback (most recent call last):
  File ".bitcoin/blockheigh.py", line 58, in &lt;module&gt;
    info = p.getblockchaininfo()
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 296, in &lt;lambda&gt;
    f = lambda *args: self._call(name, *args)
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 229, in _call
    response = self._get_response()
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 254, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1136, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
socket.timeout: timed out
</code></pre>

<p>How can I force it to wait for the response?</p>

<p>Thanks</p>

CC BY-SA 4.0
2018-06-25T14:49:09.443Z
You just need to use the socket `settimeout()` method before attempting the `connect()` so you wait for the response.
Tailer
CC BY-SA 4.0
2018-06-26T10:38:15.893Z
Is `settimeout()` part of `RawProxy`?
I can't find it
Jusoaresf
CC BY-SA 4.0
2019-08-29T08:37:29.290Z
This is a good question. How do I set a timeout when I use a library that is doing the `connect()`?
bomben
<python><bitcoin-cli>
getblockchaininfo timeout using API only
Jusoaresf
# getblockchaininfo timeout using API only

(Asked by: username_0 on 2018-06-25)

Thanks in advance.
If I call getblockchaininfo through bitcoin-cli it just works. It might take a while but it works all the time.
If I call it from within a Python Script

```
from bitcoin.rpc import RawProxy
...
# create a connection to local Bitcoin Core node
p = RawProxy()
...
info = p.getblockchaininfo()
...

```

then 8 out of 10 times it breaks...

```
~$python .bitcoin/blockheigh.py
Traceback (most recent call last):
  File ".bitcoin/blockheigh.py", line 58, in <module>
    info = p.getblockchaininfo()
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 296, in <lambda>
    f = lambda *args: self._call(name, *args)
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 229, in _call
    response = self._get_response()
  File "/home/user/.local/lib/python2.7/site-packages/bitcoin/rpc.py", line 254, in _get_response
    http_response = self.__conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1136, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
socket.timeout: timed out

```

How can I force it to wait for the response?

Thanks

**Tags:** python, bitcoin-cli

> **Comments:**
> **username_1**: You just need to use the socket `settimeout()` method before attempting the `connect()` so you wait for the response.  
> **username_0**: Is `settimeout()` part of `RawProxy`? I can't find it  
> **username_2**: This is a good question. How do I set a timeout when I use a library that is doing the `connect()`?  

---

## 0 answers

