<h2>Unable to bind (to port)</h2>
<blockquote>
<p>Unable to bind any endpoint for RPC server</p>
</blockquote>
<p>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.</p>
<p>You can check what service is bound to port 8332 using something like the <code>netstat -anp</code> command.</p>
<hr />
<h2>Errors with binding</h2>
<p>The following examples are on Windows but the Linux commands have only minor differences (e.g. Use grep instead of findstr)</p>
<p>here's one way to check what existing process is using the port</p>
<pre><code>C&gt; netstat -anb | findstr /N &quot;bitcoin 8332&quot;
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]
</code></pre>
<p>The above tells you that bitcoind is already running and it is listening to the network at port 8332, waiting for requests.</p>
<hr />
<h2>Testing RPC</h2>
<p>You can test basic connectivity as follows</p>
<pre><code>C&gt; curl http://localhost:8332/
JSONRPC server handles only POST requests
</code></pre>
<p>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 <em>not</em> get a connection refused message from curl.</p>
<hr />
<p>Here's an example that shows passing credentials and receiving an error message</p>
<pre><code>C&gt; curl -v -u user:pass -d '{&quot;method&quot;:&quot;getblockhash&quot;,&quot;params&quot;:[0],&quot;id&quot;: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'
&gt; POST / HTTP/1.1
&gt; Host: localhost:8332
&gt; Authorization: Basic dG9kYXk6dGVtcG9yYXJ5
&gt; User-Agent: curl/8.0.1
&gt; Accept: */*
&gt; Content-Length: 39
&gt; Content-Type: application/x-www-form-urlencoded
&gt;
&lt; HTTP/1.1 500 Internal Server Error
&lt; Content-Type: application/json
&lt; Date: Sun, 16 Jul 2023 14:27:47 GMT
&lt; Content-Length: 74
&lt;
{&quot;result&quot;:null,&quot;error&quot;:{&quot;code&quot;:-32700,&quot;message&quot;:&quot;Parse error&quot;},&quot;id&quot;:null}
* Connection #0 to host localhost left intact
</code></pre>
<p>In this case there is a HTTP 500 error  because bitcoind was unable to parse data.</p>
<p>You will need to specify <code>-v</code> 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</p>
<p>I changed the quoting from single to double quotes. You shouldn't have to do this on Linux, it is a Windows feature:</p>
<pre><code>C&gt; curl -u user:pass -d &quot;{\&quot;method\&quot;:\&quot;getblockhash\&quot;,\&quot;params\&quot;:[0],\&quot;id\&quot;:1}&quot; http://localhost:8332/
{&quot;result&quot;:null,&quot;error&quot;:{&quot;code&quot;:-28,&quot;message&quot;:&quot;Starting network threads…&quot;},&quot;id&quot;:1}
</code></pre>
<p>Now bitcoind doesn't have problems parsing data but says it is still busy initialising.</p>
<p>We can ask it a question that doesn't depend on blockchain state etc</p>
<pre><code>C&gt; curl -u user:pass -d &quot;{\&quot;method\&quot;: \&quot;uptime\&quot;, \&quot;params\&quot;: []}&quot; http://localhost:8332/
{&quot;result&quot;:2063,&quot;error&quot;:null,&quot;id&quot;:null}
</code></pre>
<p>bitcoind reports it has been running for 2063 seconds</p>
<pre><code>C&gt; curl -u user:pass -d &quot;{\&quot;method\&quot;: \&quot;uptime\&quot;, \&quot;params\&quot;: []}&quot; http://localhost:8332/
{&quot;result&quot;:2427,&quot;error&quot;:null,&quot;id&quot;:null}
</code></pre>
<p>Now it is 2427 seconds since bitcoind started.</p>
<p>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</p>
<pre><code>$ curl -u today:temporary -d '{&quot;method&quot;:&quot;getblockhash&quot;,&quot;params&quot;:[0],&quot;id&quot;:1}' http://localhost:8332/
{&quot;result&quot;:&quot;000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f&quot;,&quot;error&quot;:null,&quot;id&quot;:1}
</code></pre>
<p>On my PC, with many other processes running, this query can take several minutes, so you might need to adjust client timeouts.</p>

CC BY-SA 4.0
2023-07-15T16:21:24.083Z
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
CC BY-SA 4.0
2023-07-15T16:28:41.207Z
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](https://livebook.manning.com/book/grokking-bitcoin/a-using-bitcoin-cli/v-6/1) and elsewhere.
RedGrittyBrick
CC BY-SA 4.0
2023-07-15T17:15:19.617Z
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
CC BY-SA 4.0
2023-07-15T18:11:19.353Z
See extra faultfinding tip added at end of answer.
RedGrittyBrick
CC BY-SA 4.0
2023-07-16T00:08:23.427Z
I have created a JSONRPC post request: `requests.post('http://username:password@127.0.0.1:8332', json={"method":"getblockhash","params":[0],"id":1})`  and the same error occurs.
NeonTears
CC BY-SA 4.0
2023-07-16T14:41:39.553Z
I suggest testing using curl as shown in answer. That eliminates other potential problems in whatever code you may be using/writing. By "same error" I don't know which one you mean unless you explicitly quote it.
RedGrittyBrick
CC BY-SA 4.0
2023-07-19T20:30:27.120Z
I have tried all the commands you have suggested in your answer. I found that the message I get after using: `curl -v -u <user>:<password> -d '{"method":"getblockhash","params":[0],"id":1}' http://localhost
:8332/` it returns the same stuff that is returned in your example, but tells me that there is an authentication error: "Authentication error. Ignoring this". I am using the user and password from my bitcoin.conf file.
NeonTears
CC BY-SA 4.0
2023-07-19T20:51:42.723Z
@NeonTears: At some point you have to put follow on questions into a [new question](https://bitcoin.stackexchange.com/questions/ask) - I think you have reached that point because your authentication error is really a different problem from your earlier "unable to bind" problem .
RedGrittyBrick
CC BY-SA 4.0
2023-07-15T15:32:47.897Z
2024-05-27T16:51:49.590Z
2024-05-27T16:51:49.590Z
RedGrittyBrick
<p>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 <code>bitcoind</code> 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?</p>
<p>My bitcoin.conf file looks like this:</p>
<pre><code>server=1
rpcuser=&lt;username&gt;
rpcpassword=&lt;password&gt;
txindex=1
</code></pre>

CC BY-SA 4.0
2023-07-15T12:55:25.210Z
So what was in the debug log when you looked?
RedGrittyBrick
CC BY-SA 4.0
2023-07-15T15:24:23.020Z
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
<bitcoin-core><bitcoind><server>
Error: Unable to start HTTP server. See debug log for details
NeonTears
# Error: Unable to start HTTP server. See debug log for details

(Asked by: username_0 on 2023-07-15)

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

```

**Tags:** bitcoin-core, bitcoind, server

> **Comments:**
> **username_1**: So what was in the debug log when you looked?  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_1 on 2023-07-15. Score: 0 | Accepted answer

## 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.

---

## Errors with binding

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.

---

## Testing RPC

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.

> **Comments:**
> **username_0**: 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"  
> **username_1**: 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](https://livebook.manning.com/book/grokking-bitcoin/a-using-bitcoin-cli/v-6/1) and elsewhere.  
> **username_0**: 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?  
> **username_1**: See extra faultfinding tip added at end of answer.  
> **username_0**: I have created a JSONRPC post request: `requests.post('http://username:password@127.0.0.1:8332', json={"method":"getblockhash","params":[0],"id":1})`  and the same error occurs.  
> **username_1**: I suggest testing using curl as shown in answer. That eliminates other potential problems in whatever code you may be using/writing. By "same error" I don't know which one you mean unless you explicitly quote it.  
> **username_0**: I have tried all the commands you have suggested in your answer. I found that the message I get after using: `curl -v -u <user>:<password> -d '{"method":"getblockhash","params":[0],"id":1}' http://localhost :8332/` it returns the same stuff that is returned in your example, but tells me that there is an authentication error: "Authentication error. Ignoring this". I am using the user and password from my bitcoin.conf file.  
> **username_1**: @username_0: At some point you have to put follow on questions into a [new question](https://bitcoin.stackexchange.com/questions/ask) - I think you have reached that point because your authentication error is really a different problem from your earlier "unable to bind" problem .  

---

