<p>When making requests to a different network device, you need to replace <code>localhost</code> with that device's IP address. On a Raspberry Pi specifically you can use this command to find it:</p>
<pre><code>hostname -I
</code></pre>
<p>The credentials should be sent using <a href="https://en.wikipedia.org/wiki/Basic_access_authentication" rel="nofollow noreferrer">Basic access authentication</a>. This means you need to set the <code>Authorization</code> header field to <code>Basic &lt;credential&gt;</code>, where <code>&lt;credential&gt;</code> is the Base64 encoding of username and password joined by a single colon <code>:</code>.</p>

CC BY-SA 4.0
2023-07-28T00:20:56.853Z
I have a couple questions. Do I need to replace `localhost` with the pi's IP address if the two devices are connected to the same network? The request seems to go through without replacing `localhost`. Second, I have created an authorization header that looks like: `header = {'Authorization' : 'basic <base64 encoding of rpc_user:rpc_password>'}` and it does not seem to do the trick.
NeonTears
CC BY-SA 4.0
2023-07-28T16:03:28.787Z
I have tried changing `localhost` to the pi's IP address and I have created a header for the request. It is still not working. Would you have any idea why?
NeonTears
CC BY-SA 4.0
2023-07-29T04:44:40.983Z
"It is still not working" is not a helpful problem description. What error do you get? What network traffic do you observe?
David Schwartz
CC BY-SA 4.0
2023-07-29T13:00:23.203Z
Sending the request gives me the same error: "No connection could be made because the target machine actively refused it."
NeonTears
CC BY-SA 4.0
2023-07-27T22:23:42.847Z
2023-07-27T22:39:20.380Z
2023-07-27T22:39:20.380Z
Vojtěch Strnad
<p>Trying to make a POST request with python from my desktop to my Bitcoin node running on raspberrypi. The two devices are running on the same network both connected by ethernet. I have been able to make a POST request using <code>curl</code> from the node's command line (ssh from the desktop). The command looks like this:</p>
<p><code>curl -v -u &lt;rpcuser&gt;:&lt;rpcpassword&gt; -d '{&quot;method&quot;:&quot;getblockcount&quot;,&quot;params&quot;:[],&quot;id&quot;:1}' http://localhost:8332/</code></p>
<p>It gives me the output just fine, but when I write a python script from my desktop to send the same POST request, it gives me the error in the title. The python code looks like this:</p>
<p><code>request = requests.post(url=self.url, json={&quot;method&quot;:&quot;getblockhash&quot;,&quot;params&quot;:[0],&quot;id&quot;:1}, headers={'Authorization':'Basic &lt;base64 encoding of rpcuser:rpcpass&gt;'})</code></p>
<p>I have tried both the auth and the headers parameter and they both give me the same error. How can I pass in the rpcuser and password to successfully make a request?</p>

<bitcoin-core><json-rpc><server>
No connection could be made because the target machine actively refused it
NeonTears
# No connection could be made because the target machine actively refused it

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

Trying to make a POST request with python from my desktop to my Bitcoin node running on raspberrypi. The two devices are running on the same network both connected by ethernet. I have been able to make a POST request using `curl` from the node's command line (ssh from the desktop). The command looks like this:

`curl -v -u <rpcuser>:<rpcpassword> -d '{"method":"getblockcount","params":[],"id":1}' http://localhost:8332/`

It gives me the output just fine, but when I write a python script from my desktop to send the same POST request, it gives me the error in the title. The python code looks like this:

`request = requests.post(url=self.url, json={"method":"getblockhash","params":[0],"id":1}, headers={'Authorization':'Basic <base64 encoding of rpcuser:rpcpass>'})`

I have tried both the auth and the headers parameter and they both give me the same error. How can I pass in the rpcuser and password to successfully make a request?

**Tags:** bitcoin-core, json-rpc, server


---

## 1 answers

### Answer by username_1 on 2023-07-27. Score: 1

When making requests to a different network device, you need to replace `localhost` with that device's IP address. On a Raspberry Pi specifically you can use this command to find it:

```
hostname -I

```

The credentials should be sent using [Basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). This means you need to set the `Authorization` header field to `Basic <credential>`, where `<credential>` is the Base64 encoding of username and password joined by a single colon `:`.

> **Comments:**
> **username_0**: I have a couple questions. Do I need to replace `localhost` with the pi's IP address if the two devices are connected to the same network? The request seems to go through without replacing `localhost`. Second, I have created an authorization header that looks like: `header = {'Authorization' : 'basic <base64 encoding of rpc_user:rpc_password>'}` and it does not seem to do the trick.  
> **username_0**: I have tried changing `localhost` to the pi's IP address and I have created a header for the request. It is still not working. Would you have any idea why?  
> **username_2**: "It is still not working" is not a helpful problem description. What error do you get? What network traffic do you observe?  
> **username_0**: Sending the request gives me the same error: "No connection could be made because the target machine actively refused it."  

---

