Bitcoin Forum
June 29, 2024, 02:45:17 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Unable to connect to Bitcoind [regtest] with curl  (Read 71 times)
decent1984 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
August 08, 2021, 08:45:29 PM
Last edit: August 08, 2021, 09:20:31 PM by decent1984
 #1

Hi There,

This is my bitcoin.conf:

Code:
[regtest]
rpcuser=bitcoin
rpcpassword=talk

Running the below command gives me the suitable curl equivalent:

Code:
 ./bitcoin-cli -regtest help getbalances

Code:
Examples:
> bitcoin-cli getbalances
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalances", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

Now, when I run the above curl command, I get a non response like this:
Code:
~/Desktop/bitcoin-0.21.1/bin  curl --user bitcoin --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": [] }'  -H 'content-type: text/plain;'  http://127.0.0.1:18443
Enter host password for user 'bitcoin':

                                                                                                                                                                 
 ~/Desktop/bitcoin-0.21.1/bin 


Any idea on what is causing the refusal of the connection? I am running Mac and can see port 18443 taking connections

Thanks again.
decent1984 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
August 08, 2021, 09:52:53 PM
 #2

Sorry about this, I changed the username to include the password like this username:password and now it works!
NotATether
Legendary
*
Offline Offline

Activity: 1652
Merit: 6920


In memory of o_e_l_e_o


View Profile WWW
August 09, 2021, 04:03:00 AM
 #3

Sorry about this, I changed the username to include the password like this username:password and now it works!

Basically, you always have to use --user username:password format when making a JSON-RPC request to bitcoind, otherwise, you will get a 401 Unauthorized error from it because it wants you to input the password using the Authorization header. Also see the results in https://github.com/bitcoin/bitcoin/search?q=HTTP_UNAUTHORIZED.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!