<blockquote>
  <p>I'm suppose to set rpcuser, and rpcpassword on bitcoin.conf file on .bitcoin folder. Right?</p>
</blockquote>

<p>Kind of. <code>rpcuser</code> and <code>rpcpassword</code> have been deprecated in favor of cookie authentication (temporary username and password placed in the <code>.cookie</code> file) and <code>rpcauth</code>.</p>

<blockquote>
  <p>Well, when I do so I still can call bitcoin-cli without prompting any password,</p>
</blockquote>

<p>It's not supposed to. <code>bitcoin-cli</code> reads the data directory to get the information it needs. It will read your bitcoin.conf file for the username and password or it will use the <code>.cookie</code> file.</p>

<blockquote>
  <p>the code does not work</p>
</blockquote>

<p>Your code is completely wrong.</p>

<blockquote>
<pre><code>serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort)
</code></pre>
</blockquote>

<p>This is incorrect; that's not how authentication works for this.</p>

<p>Bitcoin Core uses HTTP basic auth; the username and password are not part of the URL like that. Since you are using Python Requests, here is their documentation on using HTTP Basic Authentication: <a href="http://docs.python-requests.org/en/master/user/authentication/#basic-authentication" rel="nofollow noreferrer">http://docs.python-requests.org/en/master/user/authentication/#basic-authentication</a></p>

CC BY-SA 3.0
2018-02-20T00:10:08.143Z
Thank you master. I just jumped to bitcoinrpc library, working good so far. I'll be back to this topic when the time comes. It seems it will be a long way. Thanks again.
Felipe Galaz
CC BY-SA 3.0
2018-02-19T03:34:08.333Z
2018-02-19T03:34:08.333Z
Ava Chow
<p>My problem i that I'm trying to communicate my python code with bitcoin-cli (Bitcoin ABC) and I'm suppose to set rpcuser, and rpcpassword on bitcoin.conf file on .bitcoin folder. Right?
Well, when I do so I still can call bitcoin-cli without prompting any password, and, worst, the code does not work:</p>

<pre><code>from __future__ import print_function
import requests, json

rpcPort = 8332
rpcUser = 'xxxxx'

rpcPassword = 'xxxxx'
serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort)

headers = {'content-type': 'application/json'}
payload = json.dumps({"method": 'getblock', "params": ["0000000000005e5fd51f764d230441092f1b69d1a1eeab334c5bb32412e8dc51"], "jsonrpc": "2.0"})
response = requests.get(serverURL, headers=headers, data=payload)
print(response.json()['result'])
</code></pre>

<p>My results:</p>

<pre><code>Traceback (most recent call last):
  File "/home/phglz/Desktop/pruebapython.py", line 17, in &lt;module&gt;
    print(response.json()['result'])
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/home/phglz/Desktop/pruebapython.py"]
[dir: /home/phglz/Desktop]
[path: /home/phglz/bin:/home/phglz/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
</code></pre>

<p>I'm quite lost now as you can see I'm not an expert on this.
My bitcoin.conf looks like:</p>

<pre><code>rpcuser=xxxx
rpcpassword=xxxx
daemon=1
keypool=10000
maxuploadtarget=20
maxconnections=16
</code></pre>

<p>Thanks in advance for your valued help. </p>

<bitcoind><json-rpc><bitcoin-cli>
bitcoin.conf does nothing for RPC calls
Felipe Galaz
# bitcoin.conf does nothing for RPC calls

(Asked by: username_0 on 2018-02-18)

My problem i that I'm trying to communicate my python code with bitcoin-cli (Bitcoin ABC) and I'm suppose to set rpcuser, and rpcpassword on bitcoin.conf file on .bitcoin folder. Right?
Well, when I do so I still can call bitcoin-cli without prompting any password, and, worst, the code does not work:

```
from __future__ import print_function
import requests, json

rpcPort = 8332
rpcUser = 'xxxxx'

rpcPassword = 'xxxxx'
serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort)

headers = {'content-type': 'application/json'}
payload = json.dumps({"method": 'getblock', "params": ["0000000000005e5fd51f764d230441092f1b69d1a1eeab334c5bb32412e8dc51"], "jsonrpc": "2.0"})
response = requests.get(serverURL, headers=headers, data=payload)
print(response.json()['result'])

```

My results:

```
Traceback (most recent call last):
  File "/home/phglz/Desktop/pruebapython.py", line 17, in <module>
    print(response.json()['result'])
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/home/phglz/Desktop/pruebapython.py"]
[dir: /home/phglz/Desktop]
[path: /home/phglz/bin:/home/phglz/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

```

I'm quite lost now as you can see I'm not an expert on this.
My bitcoin.conf looks like:

```
rpcuser=xxxx
rpcpassword=xxxx
daemon=1
keypool=10000
maxuploadtarget=20
maxconnections=16

```

Thanks in advance for your valued help.

**Tags:** bitcoind, json-rpc, bitcoin-cli


---

## 1 answers

### Answer by username_1 on 2018-02-19. Score: 1

> I'm suppose to set rpcuser, and rpcpassword on bitcoin.conf file on .bitcoin folder. Right?

Kind of. `rpcuser` and `rpcpassword` have been deprecated in favor of cookie authentication (temporary username and password placed in the `.cookie` file) and `rpcauth`.

> Well, when I do so I still can call bitcoin-cli without prompting any password,

It's not supposed to. `bitcoin-cli` reads the data directory to get the information it needs. It will read your bitcoin.conf file for the username and password or it will use the `.cookie` file.

> the code does not work

Your code is completely wrong.

> ```
> serverURL = 'http://' + rpcUser + ':' + rpcPassword + '@localhost:' + str(rpcPort)
>
> ```

This is incorrect; that's not how authentication works for this.

Bitcoin Core uses HTTP basic auth; the username and password are not part of the URL like that. Since you are using Python Requests, here is their documentation on using HTTP Basic Authentication: <http://docs.python-requests.org/en/master/user/authentication/#basic-authentication>

> **Comments:**
> **username_0**: Thank you master. I just jumped to bitcoinrpc library, working good so far. I'll be back to this topic when the time comes. It seems it will be a long way. Thanks again.  

---

