Getting 401 Unauthorized error when connecting to bitcoin-core with curl

8 replies 355 views
hash_2016Member
Posts: 4 · Reputation: 57
#1Feb 8, 2019, 01:42 AM
Hey everyone, I could really use some help here. Here's the issue: I’m trying to make a `curl` request, but I keep getting a "401 Unauthorized error". I checked the debug log from the daemon, and it’s not giving me much to go on. So, I started `bitcoind` like this: Oh, and I also set up a symlink for my config: My Config: I generated `rpcauth` in this way and added it to the config: I even tried swapping out `rpcauth` with this: And I did after each change to the config (not sure if that's really necessary). Yeah, I have a "t" at the end of the password everywhere. I know it’s frustrating to keep that typo, but I copied and pasted the password a bunch of times, so I’m confident there are no mistakes when I respond to curl. I’ve looked at these links for help: https://bitcoin.stackexchange.com/questions/115668/401-unauthorized-connection-using-python-bitcoinrpc https://bitcoin.stackexchange.com/questions/106395/bitcoinrpc-authproxy-jsonrpcexception-342-non-json-http-response-with-401-u https://bitcoin.stackexchange.com/questions/36433/bitcoin-rpc-works-in-bitcoin-cli-but-not-in-python-bitcoinrpc-no-json-object https://bitcoin.stackexchange.com/questions/77214/bitcoin-rpc-returning-401 I’m on Bitcoin Core version 25.0. What am I missing here? Thanks a lot.
2 Reply Quote Share
LuckyCoinLegendary
Posts: 832 · Reputation: 4795
#2Feb 8, 2019, 02:57 AM
You are getting these errors because you are not passing in credentials when calling with CURL. When you use JSON-RPC with CURL it doesn't matter whether the RPC method requires a wallet or not, if you have set an RPC username and password then you are required to pass them to curl or you will get a 401 error. Just pass --user testuser:testpassword (NOT --user by itself) or after http:// change the url to this 'testuser:testpassword@127.0.0.1:8332/'
3 Reply Quote Share
hash_2016Member
Posts: 4 · Reputation: 57
#3Feb 8, 2019, 04:35 AM
Not exactly. When I do not give the password to `curl`, it asks directly: You can see it in the very first code snippet in this thread. Nevertheless, I have just tried: re-created and added the `rpcauth` string, sent -HUP, then tried and the same result, 401 Unauthorized. And yes, the curl request was taken directly from the doc. Anything else I can try here?
0 Reply Quote Share
Posts: 38 · Reputation: 186
#4Feb 9, 2019, 10:28 PM
I searched your problem and this is one of the link that popped up. It's not the same problem as you got though
4 Reply Quote Share
hash_2016Member
Posts: 4 · Reputation: 57
#5Feb 9, 2019, 11:51 PM
I know how it sounds, but it works now without any intervention from my side, using both `--user testuser` only and with password. Without adding `--http1.1` The only idea I can think of is that the daemon reloads config not immediately but after some time. Anyway, it's solved. Thanks to everyone who tried to help.
4 Reply Quote Share
im_lynxHero Member
Posts: 515 · Reputation: 2161
#6Feb 10, 2019, 06:04 AM
To my knowledge bitcoind only reads the config file when it starts. So, if you have to make changes, you should stop bitcoind gracefully (frankly, I'm not sure if your kill -HUP does initiate a graceful exit; I always use bitcoin-cli stop for a clean termination of bitcoind), make your changes to the config file and then restart the daemon. I'm not aware of another method to trigger bitcoind to re-read its config file.
4 Reply Quote Share
im_lynxHero Member
Posts: 515 · Reputation: 2161
#7Feb 10, 2019, 08:16 AM
Some or even many unixoid daemons react on a HUP signal with a re-read of their config file. Maybe the OP thought it's the same for bitcoind when in fact it isn't. Nice find by ETFbitcoin with the cited Github issue. To allow a re-read of the config file likely opens a Pandora's box of cans of worms and a whole lot of problems with the proper internal states of bitcoind and that's why the devs dismissed the feature requests so far. Not only "Don't trust, verify!" but also "Don't assume something is working, check to be sure!".
0 Reply Quote Share
LuckyCoinLegendary
Posts: 832 · Reputation: 4795
#8Feb 11, 2019, 04:58 PM
In Bitcoin Core's case specifically, a lot of settings don't make sense to change without a full reload of the client. Take datadir or txindex for example. You can't really change these at runtime without discarding the application state (former) or incurring a short but huge performance penalty (latter). Or what if you change the RPC url or authentication? Then you'd have to wait for existing RPC calls to finish - which may be long running like importmulti - or abort them. SIGHUP reloading works best for simple programs, not those with complex states such as a full blockchain.
4 Reply Quote Share
hash_2016Member
Posts: 4 · Reputation: 57
#9Feb 12, 2019, 03:34 PM
It was mentioned in the link sent by @pinggoki. Re: reloading: yep, lessons learned.
3 Reply Quote Share
?Reply
Sign in to reply to this topic

Related topics