rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
313 stars 231 forks source link

JSON-RPC error: transport error: unexpected HTTP code: 400 #323

Open CITGuru opened 6 months ago

CITGuru commented 6 months ago

I keep getting this error when making RPC calls with this library.

pub async fn fetch_new_blocks() -> Result<(), Box<dyn Error>> {
    let rpc_url = "rpc_url";

    let client = Client::new(&rpc_url, Auth::None).expect("Failed to create client");
    let best_block_hash = client.get_best_block_hash()?;
    println!("best block hash: {}", best_block_hash);
    let current_height = client.get_block_count()?;
    println!("{}", current_height);
    Ok(())
}

Error:

JSON-RPC error: transport error: unexpected HTTP code: 400

PS: My RPC URL does not have a username and password. The URL contains a token for auth

apoelstra commented 6 months ago

Is it an HTTPS URL?

CITGuru commented 6 months ago

Yes

On Thu, Dec 14, 2023, 2:47 PM Andrew Poelstra @.***> wrote:

Is it an HTTPS URL?

— Reply to this email directly, view it on GitHub https://github.com/rust-bitcoin/rust-bitcoincore-rpc/issues/323#issuecomment-1855884787, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5WNRXQPNCDURZ2G6H6XH3YJL7OZAVCNFSM6AAAAABAUMPC7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJVHA4DINZYG4 . You are receiving this because you authored the thread.Message ID: @.***>

apoelstra commented 6 months ago

Unfortunately this library doesn't support HTTPS right now because the underlying JSONRPC library (rust-jsonrpc) has only been recently updated to support a HTTPS-supporting backend (minreq).

We need to update our copy of rust-jsonrpc and enable the minreq feature on it.

CITGuru commented 5 months ago

@apoelstra is it something you need help with?

mprakhov17 commented 2 months ago

Hello, do you have any updates on this ticket? It's weird that rust-bitcoincore-rpc can't work with HTTPS

apoelstra commented 2 months ago

Bitcoin Core doesn't use HTTPS..

But anyway yes, now rust-jsonrpc has a minreq backend which supports HTTPS.