@mollya

Почему не работает reqwest в rust?

Привет, при работе с reqwest в rust выдает ошибку:
error[E0433]: failed to resolve: maybe a missing crate `reqwest`?
 --> main.rs:1:5
  |
1 | use reqwest::blocking::*;
  |     ^^^^^^^ maybe a missing crate `reqwest`?
  |
  = help: consider adding `extern crate reqwest` to use the `reqwest` crate

error[E0433]: failed to resolve: maybe a missing crate `reqwest`?
 --> main.rs:2:5
  |
2 | use reqwest::header::USER_AGENT;
  |     ^^^^^^^ maybe a missing crate `reqwest`?
  |
  = help: consider adding `extern crate reqwest` to use the `reqwest` crate

error[E0432]: unresolved import `reqwest::header::USER_AGENT`
 --> main.rs:2:5
  |
2 | use reqwest::header::USER_AGENT;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0433]: failed to resolve: use of undeclared type `Client`
  --> main.rs:10:22
   |
10 |     println!("{:?}", Client::new().get(URL).header(USER_AGENT, CUSTOM_USER_AGENT).send().unwrap().text().unwrap());
   |                      ^^^^^^ use of undeclared type `Client`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.


Код:
use reqwest::blocking::*;
use reqwest::header::USER_AGENT;



const URL: &str = "https://finance.yahoo.com/quote/BTC-USD/history/"; 
const CUSTOM_USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.226 Safari/537.36";

fn main() {
    println!("{:?}", Client::new().get(URL).header(USER_AGENT, CUSTOM_USER_AGENT).send().unwrap().text().unwrap());
}


Cargo.toml:
[package]
name = "app"
version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { version = "0.12.7", features = ["blocking"] }
scraper = "0.20.0"
csv = "1.3.0"
  • Вопрос задан
  • 66 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы