0

How do I connect to Bitcoin Core using python-bitcoinrpc and a ~/.bitcoin/.cookie file?

This issue commenter claims this is how to do it:

rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8332"%("__cookie__", "yourpassword") 

This doesn't make sense, since .cookie files don't require a password, do they?

2 Answers 2

1
from bitcoinrpc.authproxy import AuthServiceProxy with open("/home/yourusername/.bitcoin/.cookie", "r") as f: cookie = f.read().strip() rpc_connection = AuthServiceProxy(f"http://{cookie}@127.0.0.1:8332") 

The .cookie file contains both username and password separated by a colon. You read the entire contents and use it as the authentication string in the URL. No separate password needed.

0

That syntax makes sense. See this.

You could do, equivalently:

rpc_connection = AuthServiceProxy('http://<LINE_FROM_COOKIE_FILE>@127.0.0.1:8332') 

E.g.,

rpc_connection = AuthServiceProxy('http://__cookie__:02a4a6120f20bbf2630b39bf28e30683f4a6325c6831c9819ff64d2c5a466582@127.0.0.1:8332') 

The 64 hex digits after the ':' is the "password" (cookie contents).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.