0

I have been looking around quite a bit about ways to solve this error and none of them have worked. To give some context, I am running a full node on a raspberry pi and everything is working just fine from the command line. I am able to write bitcoin-cli commands and it gives me the results just fine. When I write bitcoind in the command line to show if everything is working, it says that it is unable to an http server (the error in the title). Does anyone know how to fix this?

My bitcoin.conf file looks like this:

server=1
rpcuser=<username>
rpcpassword=<password>
txindex=1
2
  • So what was in the debug log when you looked? Jul 15, 2023 at 12:55
  • Binding RPC on address ::1 port 8332 failed. Binding RPC on address 127.0.0.1 port 8332 failed. Unable to bind any endpoint for RPC server Error: Unable to start HTTP server. See debug log for details.
    – NeonTears
    Jul 15, 2023 at 15:24

1 Answer 1

0

Unable to bind (to port)

Unable to bind any endpoint for RPC server

This is a very common error for network services of all kinds. The most common causes are that there is already another service bound to the port (8332 in this case) or that the user lacks permissions.

You can check what service is bound to port 8332 using something like the netstat -anp command.


Troubleshooting

The following examples are on Windows but the Linux commands have only minor differences (e.g. Use grep instead of findstr)

here's one way to check what existing process is using the port

C> netstat -anb | findstr /N "bitcoin 8332"
63: [bitcoind.exe]
65: [bitcoind.exe]
67: [bitcoind.exe]
69: [bitcoind.exe]
70:  TCP    127.0.0.1:8332         0.0.0.0:0              LISTENING
71: [bitcoind.exe]
132:  TCP    [::1]:8332             [::]:0                 LISTENING
133: [bitcoind.exe]

The above tells you that bitcoind is already running and it is listening to the network at port 8332, waiting for requests.

You can test basic connectivity as follows

C> curl http://localhost:8332/
JSONRPC server handles only POST requests

Note that I deliberately don't send credentials or a valid request. However the bitcoind receives the request and tells me something about what it doesn't like. That proves the bitcoind HTTP service is working. I do not get a connection refused message from curl.


Here's an example that shows passing credentials and receiving an error message

C> curl -v -u user:pass -d '{"method":"getblockhash","params":[0],"id":1}' http://localhost:8332/
*   Trying 127.0.0.1:8332...
* Connected to localhost (127.0.0.1) port 8332 (#0)
* Server auth using Basic with user 'user'
> POST / HTTP/1.1
> Host: localhost:8332
> Authorization: Basic dG9kYXk6dGVtcG9yYXJ5
> User-Agent: curl/8.0.1
> Accept: */*
> Content-Length: 39
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 500 Internal Server Error
< Content-Type: application/json
< Date: Sun, 16 Jul 2023 14:27:47 GMT
< Content-Length: 74
<
{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}
* Connection #0 to host localhost left intact

In this case there is a HTTP 500 error because bitcoind was unable to parse data.

You will need to specify -v to be sure to see the HTTP error messages, but it isn't needed once you have JSON responses working. We can drop the -v option to reduce the clutter

I changed the quoting from single to double quotes. You shouldn't have to do this on Linux, it is a Windows feature:

C> curl -u user:pass -d "{\"method\":\"getblockhash\",\"params\":[0],\"id\":1}" http://localhost:8332/
{"result":null,"error":{"code":-28,"message":"Starting network threads…"},"id":1}

Now bitcoind doesn't have problems parsing data but says it is still busy initialising.

We can ask it a question that doesn't depend on blockchain state etc

C> curl -u user:pass -d "{\"method\": \"uptime\", \"params\": []}" http://localhost:8332/
{"result":2063,"error":null,"id":null}

bitcoind reports it has been running for 2063 seconds

C> curl -u user:pass -d "{\"method\": \"uptime\", \"params\": []}" http://localhost:8332/
{"result":2427,"error":null,"id":null}

Now it is 2427 seconds since bitcoind started.

If I switch to WSL for no particular reason other than to try an RPC call using Linux, bitcoind is has finished initialising and can answer questions about blockchain data

$ curl -u today:temporary -d '{"method":"getblockhash","params":[0],"id":1}' http://localhost:8332/
{"result":"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f","error":null,"id":1}

On my PC, with many other processes running, this query can take several minutes, so you might need to adjust client timeouts.

8
  • The PID/program name that is listed on 127.0.0.1:8332 is bitcoind. Does this mean that it is connected to localhost? Also state of the program is "LISTEN"
    – NeonTears
    Jul 15, 2023 at 16:21
  • Its already running and you shouldn't try to start another copy running. You communicate with the current bitcoind using bitcoin-cli or another client program. As described here and elsewhere. Jul 15, 2023 at 16:28
  • I have code sending a command to this http server: AuthServiceProxy(f'http://{rpc_user}:{rpc_password}@127.0.0.1:{rpc_port}') But it tells me that the target machine refused it. Would this be because of this "Unable to start http server" error?
    – NeonTears
    Jul 15, 2023 at 17:15
  • See extra faultfinding tip added at end of answer. Jul 15, 2023 at 18:11
  • I have created a JSONRPC post request: requests.post('http://username:[email protected]:8332', json={"method":"getblockhash","params":[0],"id":1}) and the same error occurs.
    – NeonTears
    Jul 16, 2023 at 0:08

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.