bitcoin: Bitcoind ThreadRPCServer authentication problems

Describe the issue

If I try to connect with bitcoin-cli or any other client I get 401. I use normal username/password and always get 401 (localhost and remote). Authentication over basic auth cookie via bitcoin-cli works.

debug.log Msg: 2017-02-01 06:59:45 ThreadRPCServer incorrect password attempt from 127.0.0.1:41472 bitcoin-cli Msg: error: incorrect rpcuser or rpcpassword (authorization failed)

Can you reliably reproduce the issue?

If so, please list the steps to reproduce below:

  1. Configure bitcoind (with my config) and start bitcoind
  2. bitcoin-cli -rpcuser=REPLACED -rpcpassword=REPLACED -rpcconnect=127.0.0.1 -rpcport=8332 -datadir=/data/btc getinfo

Expected behaviour

Successful authentication

Actual behaviour

HTTP Code 401

What version of bitcoin-core are you using?

List the version number/commit ID, and if it is an official binary, self compiled or a distribution package such as PPA.

  1. Bitcoin Core Daemon version v0.13.2 Arch Linux distribution package
  2. Bitcoin Core Daemon version v0.13.99.0-e99f0d7ad self compiled
  with wallet   = yes
  with gui / qt = yes
    qt version  = 5
    with qr     = yes
  with zmq      = yes
  with test     = yes
  with bench    = yes
  with upnp     = yes
  debug enabled = no

Machine specs:

  • OS: Arch Linux x64
  • CPU: Xeon 4 cores 2 threads
  • RAM: 16G
  • Disk size: 16T RAID5
  • Disk Type (HD/SDD): HD

Any extra information that might be useful in the debugging process.

This is normally the contents of a debug.log or config.log file. Raw text or a link to a pastebin type site are preferred.

My bitcoind config:

server=1
listen=1
rpcuser=REPLACED
rpcpassword=REPLACED
rpcbind=127.0.0.1:8332
rpcthreads=8
rpcallowip=127.0.0.1

HTTP request/response (from tcpdump):

POST / HTTP/1.1
Authorization: Basic UkVQTEFDRUQ6UkVQTEFDRUQ=
Host: REPLACED:8332
Accept: */*
Content-type: application/json
Content-Length: 39

{"method":"getinfo","params":[],"id":1}
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="jsonrpc"
Date: Wed, 01 Feb 2017 07:05:40 GMT
Content-Length: 0
Content-Type: text/html; charset=ISO-8859-1

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

I was running it on Ubuntu 16.

I had rpcuser and rpcpassword in the config file, but I was getting 401 error when I called the jaon-rpc api.

I found a workaround by providing -rpcuser=REPLACED -rpcpassword=REPLACED when I launched the bitcoind.

Hope this is still relevant and useful.

@gr33k That’s an unrelated issue. Since 0.18 you need to put rpcbind explicitly if you want to listen on more than localhost.

For future googlers: the password should not contain the pound sign (#) as this is treated as a comment!

I am having this issue on my mac OSX High Sierra. The rpcuser and rpcpassword set in the conf file are not being used by the rpcserver.

Failure

curl -v --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://<username>:<password>=@127.0.0.1:9245/

Success

curl -v --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://__cookie__:Cq113bVyv+MNbOp5krK5rersYN9JPWAiheaQr5z4hhw=@127.0.0.1:9245/

Can also be done via CLI

Failure

./bitcoin-cli -rpcuser=<username> -rpcpassword=<password> -rpcconnect=127.0.0.1 -rpcport=9245 getinfo

Sucess

./bitcoin-cli -rpcuser=__cookie__ -rpcpassword=Cq113bVyv+MNbOp5krK5rersYN9JPWAiheaQr5z4hhw= -rpcconnect=127.0.0.1 -rpcport=9245 getinfo

On Windows, using Bitcoin Core 0.13.2, this works fine (rpc/rpc): bitcoin-cli.exe -rpcuser=rpc -rpcpassword=rpc -testnet=1 getinfo

It’s either specific to your build or maybe some of the parameters and arguments have issues. Simple RPC-focused test without using config files:

C:\bitcoin\bin>bitcoin-qt.exe -server=1 -rpcuser=rpc -rpcpassword=rpc -datadir=c:\bitcoin # wait 1 min
C:\bitcoin\bin>bitcoin-cli.exe -rpcuser=rpc -rpcpassword=rpc getinfo
{
  "version": 130200,
  "protocolversion": 70015,
  "walletversion": 60000,
  "balance": 0.00000000,
  "blocks": 641,
  "timeoffset": 0,
  "connections": 2,
  "proxy": "",
  "difficulty": 1,
  "testnet": false,
  "keypoololdest": 1416112331,
  "keypoolsize": 101,
  "paytxfee": 0.00000000,
  "relayfee": 0.00001000,
  "errors": ""
}