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)

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
  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 that the socket timeout can be set but I wonder if I can do this if I use a library for the connection.


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:

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
| improve this answer | |
  • 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. – Ben Aug 29 '19 at 10:27
  • update the answer – vincenzopalazzo Aug 29 '19 at 10:59

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.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.