reqwest

Do a synchronous http client fetch within an actix thread

对着背影说爱祢 提交于 2021-02-11 06:57:19
问题 I have an actix endpoint, and I need to do a synchronous http client fetch to get some results, and return some data. My endpoints cannot use async , so I can't use any .await methods. I've tried using reqwests blocking client in my endpoint like so: { ... let res = reqwest::blocking::get(&fetch_url)? .json::<MyResp>()?; ... But it gives me the error: thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block

Do a synchronous http client fetch within an actix thread

吃可爱长大的小学妹 提交于 2021-02-11 06:57:19
问题 I have an actix endpoint, and I need to do a synchronous http client fetch to get some results, and return some data. My endpoints cannot use async , so I can't use any .await methods. I've tried using reqwests blocking client in my endpoint like so: { ... let res = reqwest::blocking::get(&fetch_url)? .json::<MyResp>()?; ... But it gives me the error: thread 'main' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block

Why do the bytes of a PNG image downloaded with reqwest differ from those downloaded with Python?

偶尔善良 提交于 2021-02-05 11:51:42
问题 I'm trying to use reqwest library to download a PNG file, but when I download it I see a strange behaviour respect other programming languages like: Python. For instance: let content = reqwest::get("https://www.google.es/images/searchbox/desktop_searchbox_sprites302_hr.png").await?; If I print the result as a bytes array ( println!("{:?}", content.text().await?.as_bytes() ); [ 191, 189, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 40, 0, 0, 0, 82, 8, 3, 0, 0, 0, 17, 191,

Why does the reqwest HTTP library return binary data instead of a text body?

≯℡__Kan透↙ 提交于 2020-08-05 07:44:06
问题 I am trying to perform a HTTP GET request with reqwest and print the response body to STDOUT. This works for most websites, but it returns weird binary output for amazon.com: #[tokio::main] async fn main() { run().await; } async fn run() { let url = "https://www.amazon.com/PNY-GeForce-Gaming-Overclocked-Graphics/dp/B07GJ7TV8L/"; let resp = reqwest::get(url).await.unwrap(); let text = resp.text().await.unwrap(); println!("{}", text); } Why would resp.text().await.unwrap() return binary data

The trait `std::future::Future` is not implemented for `std::result::Result<reqwest::Response, reqwest::Error>`

北慕城南 提交于 2020-05-29 09:43:24
问题 I'm trying to run basic reqwest example: extern crate reqwest; extern crate tokio; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let res = reqwest::Client::new() .get("https://hyper.rs") .send() .await?; println!("Status: {}", res.status()); let body = res.text().await?; println!("Body:\n\n{}", body); Ok(()) } Error that I'm getting: --> src/main.rs:6:15 | 6 | let res = reqwest::Client::new() | _______________^ 7 | | .get("https://hyper.rs") 8 | | .send() 9 | | .await?; | |__

The trait `std::future::Future` is not implemented for `std::result::Result<reqwest::Response, reqwest::Error>`

烈酒焚心 提交于 2020-05-29 09:41:58
问题 I'm trying to run basic reqwest example: extern crate reqwest; extern crate tokio; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { let res = reqwest::Client::new() .get("https://hyper.rs") .send() .await?; println!("Status: {}", res.status()); let body = res.text().await?; println!("Body:\n\n{}", body); Ok(()) } Error that I'm getting: --> src/main.rs:6:15 | 6 | let res = reqwest::Client::new() | _______________^ 7 | | .get("https://hyper.rs") 8 | | .send() 9 | | .await?; | |__