0

I am unable to connect to my server despite trying for days. I have asked posted questions and my .conf file and my python code and despite this no one has been able to give me a reason why it is not connecting.

I am able to connect to the port using telnet 127.0.0.1 [port_num]

And I am decently sure I have opened the ports correctly. Nestats -a shows them open. I have opened them both for incoming and outgoing, both for my router, and for my firewall. And when I remove the rules, I immediately get a different error stating the host refused connections. But when i have those rules engaged I instead get the following error...

(.venv) D:\PROJECTS\python38_env_bitcoin\src\hellobitcoin101>python bitcoin104.py
<bitcoinrpc.authproxy.AuthServiceProxy object at 0x0000021E5BB11730>
Traceback (most recent call last):
  File "bitcoin104.py", line 10, in <module>
    best_block_hash = rpc_connection.getbestblockhash()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 139, in __call__
    response = self._get_response()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 179, in _get_response
    http_response = self.__conn.getresponse()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

I am trying use use the user password using rpcauth.. so in my .conf file I have something like...

rpcuser=myname
rpcauth=myname:fef852a5c3e764a3a4e7fcaa283b2f1f$eadb370e8d7705d8c960570c13b49372d1a3780aa3e1ea5013908271035d4ee9

I am not sure if this is the proper usage. I got the hash using... python ./rpcauth.py myname mypassword

I previous tried a setup like....

rpcuser=myname
rpcpassword=mypassword

What is interesting it I also sometimes get a connection without response error as well without having changed anything...

For instance...

PS D:\PROJECTS\python38_env_bitcoin\src\hellobitcoin101> python .\bitcoin104.py
>>
<bitcoinrpc.authproxy.AuthServiceProxy object at 0x000002482E142730>
Traceback (most recent call last):
  File ".\bitcoin104.py", line 10, in <module>
    best_block_hash = rpc_connection.getbestblockhash()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 139, in __call__
    response = self._get_response()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 179, in _get_response
    http_response = self.__conn.getresponse()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 276, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
PS D:\PROJECTS\python38_env_bitcoin\src\hellobitcoin101> python .\bitcoin104.py
>>
<bitcoinrpc.authproxy.AuthServiceProxy object at 0x000001F7602E2730>
Traceback (most recent call last):
  File ".\bitcoin104.py", line 10, in <module>
    best_block_hash = rpc_connection.getbestblockhash()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 139, in __call__
    response = self._get_response()
  File "D:\PROJECTS\python38_env_bitcoin\.venv\lib\site-packages\bitcoinrpc\authproxy.py", line 179, in _get_response
    http_response = self.__conn.getresponse()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 1344, in getresponse
    response.begin()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\http\client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "c:\users\hanso\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

i have searched online and there is very little it seems in terms of examples of a properly setup .conf file and corresponding python rpc authority call...

Like so...

rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8334"%("myname","mypassword"))
best_block_hash = rpc_connection.getbestblockhash()
best_block_hash

It fails on the second line above, ie best_block_hash = rpc_connection.getbestblockhash()

At this point I think i have tried everything I can possible think of.

My gut is saying it is something I might be doing wrong with the user password perhaps. But I have tried many different configurations, many different passwords. Restarting the node each time and loading in the changed .conf file, and running the python script again. And all I get is the timed out, or no response no matter what i do now.. Then if I mess with the port it I get the connection refused by host error instead.

If I could maybe see an example online of a properly setup .conf file with the exact rpsuser and rpcpassword text, and the same in the python rpc socket setup. I have no idea if maybe I shouldn't be putting "" around something, or should be and I am not, and that has been the issue. Or perhaps I need to be using the rpcauth in a different way...?

Any help would be greatly greatly appreciated... Thanks for reading this far regardless.

0

1 Answer 1

0

Minimal bitcoin.conf

You quoted

  File "c:\users\hanso\appdata\local\programs\python\python38\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

Pay attention to that last line


With this bitcoin.conf

rpcuser=today
rpcpassword=temporary

This python script, in a file named GetBlockCount.py

from bitcoinrpc.authproxy import AuthServiceProxy

rpc_user ="today"
rpc_password="temporary"
rpc_port = "8332"

rpc_client = AuthServiceProxy("http://%s:%[email protected]:%s"%(rpc_user, rpc_password, rpc_port), timeout=120)

block_count = rpc_client.getblockcount()
print(block_count)

Produces this result

C> python GetBlockCount.py
827496

Take careful note of that timeout=120 in the script.


Notes

The above result was produced on an old and ordinary PC purchased in 2015 running Windows 10. It has an i7 processor, 8GB RAM and an ordinary HDD (not SSD).

The RPC service was provided by bitcoin-qt with RPC enabled in settings, options, main.

At the time I ran the script, Bitcoin core was about 1500 blocks behind. The script took nearly two minutes to return a result. It also produced a timeout before I increased the bitcoinrpc library default from 30 to 120.

After Bitcoin Core caught up, I find the python script returns a result in about three seconds. It is faster on subsequent invocations.

So when experiencing timeout error messages, I would either increase the timeout in the script or wait until Bitcoin core has fully synchronised.

The above is somewhat anecdotal. I wouldn't put too much weight on a single informal experiment.


Related

4
  • Thanks man. I tried this, exactly word for word. Changed my conf to match the rpcuser etc you posted. And then ran your python code exactly it hung for while, I assume 120 seconds, then it kicked out with the same error. I tried a couple more times, and now the exact same code doesnt' even wait 120 seconds, it comes back instantly now... which might be a clue what is going on but I have no idea what that might mean. At this point I am completely lost with what I could be doing wrong. Feb 4 at 3:28
  • I am going to completely uninstall my bitcoin core node, and start from scratch. It will take a day or two to reload the blockchain data. I doubt it will help, but at this point I feel like I have tried everything. Just to confirm I don't need to do anything but run bitcoin-qt.exe in the bitcoin directory to launch the node correct. Ie I don't need to be messing with the bitcoind..exe daemon exe? I assume that the bitcoin-qt.exe is running the node? Feb 4 at 3:29
  • Thanks again for the help. I do appreciate it. Was hoping it would work... I am reinstalling the node. I am curious do I have to wait until the entire node is caught up, or can i try to connect to the node before it is up to date with the latest transactions? Feb 4 at 4:06
  • I have added some notes to the end of my answer. Feb 4 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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