0

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

  • You just need to use the socket settimeout() method before attempting the connect() so you wait for the response. – Adam Jun 25 '18 at 14:49
  • Is settimeout() part of RawProxy? I can't find it – Jusoaresf Jun 26 '18 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.