json rpc – Bitcoin Core RPC server not working
I downloaded, installed and ran a Bitcoin Core node and it’s working fine as long as people are connecting to port 8333. However, I don’t seem to be able to connect directly from the same machine using the Python bitcoinrpc library…
Here is my .conf file:
port=8333
timeout=10000
printtoconsole=1
chain=main
rpcuser=one
rpcport=8334
#rpcauth=one:xxxxxx
server=1
coinstatsindex=1
daemon=1
txindex=1
And my Python app…
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
# rpc_user and rpc_password are set in the bitcoin.conf file
rpc_user = "one"
rpc_password = "two"
rpc_connection = AuthServiceProxy("http://%s:%(email protected):8334"%("one","two"))
best_block_hash = rpc_connection.getbestblockhash()
And when it runs, it fails online.
best_block_hash = rpc_connection.getbestblockhash()
The following error occurred:
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
I checked all ports and I’m confident they are working. It works via telnet. netstat -a shows that the port is listening when I open a Bitcoin Core node, and if I try a different port it complains with a different error. Host connection refused. So I’m 99% sure that the port forwarding and firewall are open on the desired ports. Port 8333 for external connections displays logs of people connecting to the server. So I’m pretty sure it’s not your computer, firewall, or router that isn’t allowing connections through the port.
This leaves me with the wrong password. I’ve changed my setup to use a simple one or two use ID and password for testing purposes, so I’ll post it here so I can show you exactly what I’m doing word for word in the conf and Python script.
I’m really banging my head against the wall… I wonder if it has something to do with rpcauth… I ran it, created a hash, and tried to use it as a fallback in my http://pass:(email protected),1:8334 connection. But that doesn’t seem to work either. But funny enough, if I enter an obviously wrong password, I get the same error as now. However, if I change the IP address, it fails on the AuthServiceProxy creation line instead. And the problem was that my computer host refused the connection. So all of this points to the node node where I like my user id and/or password, but I can’t find any examples that would allow me to verify that I’ve set them up correctly for node in the .conf file before starting node, or that I’m doing it. Is there something wrong with my Python script?