DaniPopes / dexscreener

A Rust Dexscreener HTTP API client
MIT License
3 stars 4 forks source link

invalid URL, scheme is not http #2

Closed TQMatvey closed 10 months ago

TQMatvey commented 10 months ago

The following quite simple code

use dexscreener::Client;
use tokio;

#[tokio::main]
async fn main() {
    get_pair().await;
}

async fn get_pair() {
    // Create a new client instance
    let client = Client::new();
    // Define the token addresses
    let token_addresses = [
        "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
        "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
    ];
    // Get the pairs from the client
    let result = client.tokens(token_addresses).await;

    // Handle the result
    match result {
        Ok(response) => {
            if let Some(pairs) = response.pairs {
                println!("{:?}", pairs);
            } else {
                println!("No pairs found");
            }
        }
        Err(e) => {
            println!("Error occurred: {:?}", e);
        }
    }
}

produces an error

Error occurred: Reqwest(reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.dexscreener.com")), port: None, path: "/latest/dex/tokens/0x2170Ed0880ac9A755fd29B2688956BD959F933F8,0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", query: None, fragment: None }, source: hyper::Error(Connect, "invalid URL, scheme is not http") })
DaniPopes commented 10 months ago

You need to enable HTTPS support in reqwest, see reqwest TLS features