<p>Two important errors in the output you present are:</p>
<pre><code>FileNotFoundError: [Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie'
</code></pre>
<p>and</p>
<pre><code>ValueError: Cookie file unusable ([Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie') and rpcpassword not specified in the configuration file: '/home/pariya/.bitcoin/bitcoin.conf'
</code></pre>
<p>The later says that you did not provide <em>RPC password</em> via configuration file and cookie file is missing too.</p>
<p>You probably missed some init steps in your code (to login to bitcoind RPC server) or you should create a file <code>/home/pariya/.bitcoin/bitcoin.conf</code> and configure RPC password there:</p>
<pre><code>rpcuser=johndoe
rpcpassword=enteryourpassword
</code></pre>
<p>Please note that the values of these parameters must match those configured in bitcoind obviously.</p>

CC BY-SA 4.0
2023-05-09T17:35:28.727Z
I don't know why it is searching for the file in my home directory. My bitcoin directory is on the external hard drive. I also have the conf file with a set rpcuser and rpcpassword in it.
Pariya
CC BY-SA 4.0
2023-05-10T08:54:59.297Z
Although `bitcoind` is placed on external drive, your code and the python library acts as a client and it look for the config in the default location.

Also, if the package you use is `bitcoin` (see https://pypi.org/project/bitcoin/), it's not maintained anymore and it could be quite outdated. I would look for some up-to-date package, e.g. `bitcoin-utils` (https://pypi.org/project/bitcoin-utils/) could do the same thing you are looking for.
Vojta Myslivec
CC BY-SA 4.0
2023-05-09T14:40:50.550Z
2023-05-09T14:40:50.550Z
Vojta Myslivec
<p>Your script seems to not be able to find the cookie file, necessary to authenticate to <code>bitcoind</code>. Most likely <code>bitcoind</code> is not running on the right network.</p>

CC BY-SA 4.0
2023-05-09T14:35:51.197Z
2023-05-09T14:35:51.197Z
Antoine Poinsot
<p>I'm trying to connect to bitcoind with python3. I'm currently following the instructions of Antonopolous book.</p>
<p>This is my code on an IDE:</p>
<pre class="lang-python prettyprint-override"><code>from bitcoin.rpc import RawProxy
p = RawProxy()
info = p.getinfo()
print(info['blocks'])
</code></pre>
<p>Unfortunately I only get warnings:</p>
<pre><code>/home/pariya/python_pr/venv/bin/python /home/pariya/python_pr/main.py 
Traceback (most recent call last):
  File &quot;/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py&quot;, line 190, in __init__
    with open(cookie_file, 'r') as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/home/pariya/python_pr/main.py&quot;, line 5, in &lt;module&gt;
    p = RawProxy()
  File &quot;/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py&quot;, line 313, in __init__
    super(RawProxy, self).__init__(service_url=service_url,
  File &quot;/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py&quot;, line 197, in __init__
    raise ValueError('Cookie file unusable (%s) and rpcpassword not specified in the configuration file: %r' % (err, btc_conf_file))
ValueError: Cookie file unusable ([Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie') and rpcpassword not specified in the configuration file: '/home/pariya/.bitcoin/bitcoin.conf'

Process finished with exit code 1
</code></pre>
<p>I'm running bitcoind on an external hard drive. Is something missing in my code?</p>
<p>Thankful for any help.</p>

<bitcoind><json-rpc><python>
Bitcoind python connection
Pariya
# Bitcoind python connection

(Asked by: username_0 on 2023-05-09)

I'm trying to connect to bitcoind with python3. I'm currently following the instructions of Antonopolous book.
This is my code on an IDE:
from bitcoin.rpc import RawProxy
p = RawProxy()
info = p.getinfo()
print(info['blocks'])

Unfortunately I only get warnings:
/home/pariya/python_pr/venv/bin/python /home/pariya/python_pr/main.py 
Traceback (most recent call last):
  File "/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py", line 190, in __init__
    with open(cookie_file, 'r') as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pariya/python_pr/main.py", line 5, in 
    p = RawProxy()
  File "/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py", line 313, in __init__
    super(RawProxy, self).__init__(service_url=service_url,
  File "/home/pariya/python_pr/venv/lib/python3.10/site-packages/bitcoin/rpc.py", line 197, in __init__
    raise ValueError('Cookie file unusable (%s) and rpcpassword not specified in the configuration file: %r' % (err, btc_conf_file))
ValueError: Cookie file unusable ([Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie') and rpcpassword not specified in the configuration file: '/home/pariya/.bitcoin/bitcoin.conf'

Process finished with exit code 1

I'm running bitcoind on an external hard drive. Is something missing in my code?
Thankful for any help.

**Tags:** bitcoind, json-rpc, python


---

## 2 answers

### Answer by username_1 on 2023-05-09. Score: 1

Two important errors in the output you present are:
FileNotFoundError: [Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie'

and
ValueError: Cookie file unusable ([Errno 2] No such file or directory: '/home/pariya/.bitcoin/.cookie') and rpcpassword not specified in the configuration file: '/home/pariya/.bitcoin/bitcoin.conf'

The later says that you did not provide RPC password via configuration file and cookie file is missing too.
You probably missed some init steps in your code (to login to bitcoind RPC server) or you should create a file /home/pariya/.bitcoin/bitcoin.conf and configure RPC password there:
rpcuser=johndoe
rpcpassword=enteryourpassword

Please note that the values of these parameters must match those configured in bitcoind obviously.

> **Comments:**
> **username_0**: I don't know why it is searching for the file in my home directory. My bitcoin directory is on the external hard drive. I also have the conf file with a set rpcuser and rpcpassword in it.  
> **username_1**: Although `bitcoind` is placed on external drive, your code and the python library acts as a client and it look for the config in the default location.  Also, if the package you use is `bitcoin` (see https://pypi.org/project/bitcoin/), it's not maintained anymore and it could be quite outdated. I would look for some up-to-date package, e.g. `bitcoin-utils` (https://pypi.org/project/bitcoin-utils/) could do the same thing you are looking for.  

---

### Answer by username_2 on 2023-05-09. Score: 0

Your script seems to not be able to find the cookie file, necessary to authenticate to `bitcoind`. Most likely `bitcoind` is not running on the right network.


---

