1

When I try to get data from my elasticsearch API the following error appears:

thread 'main' panicked at 'failed to get response: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(9200), path: "/part_of_speech", query: None, fragment: None }, source: hyper::Error(Connect, Error { code: -67843, message: "The certificate was not trusted." }) }', src/main.rs:15:10

No, not a duplicate of How to get body of response with reqwest? since that one is not using authentication and the solution given did not work.

The following is the code from which I expect the JSON output of the API

#[tokio::main]
async fn main() {
   let health = get_health().await;
}

async fn get_health() {
    let client = Client::new();
    let res = client
        .get("https://localhost:9200/speaker")
        .basic_auth("elastic", Some("7*7C68392TXAENxKRot"))
        .send()
        .await
        .expect("failed to get response")
        .text()
        .await
        .expect("failed to get payload");

    println!("{}", res);
}

What I have tried:

  • I added the method headers but the same error appeared

      .headers(construct_headers())
        fn construct_headers() -> HeaderMap {
      let mut headers = HeaderMap::new();
      headers.insert(AUTHORIZATION, HeaderValue::from_static("Basic ZWxhc3RpYzo3KjdDYVJUcGliVFhBRU54S1JvdA=="));
      headers
    

    }

Xavi Font
  • 296
  • 4
  • 19

0 Answers0