I am testing a web api using the reqwest
crate. I get the following error after a certain number of requests.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(8000), path: "/create_my_profile", query: None, fragment: None }, fragment: None } source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 49, kind: AddrNotAvailable, message: "Can't assign requested address" })) }
How can I handle this? I have searched github issues, etc., but could not find a solution.
Steps to reproduce:
- os -> macos
const BASEURL: &str = "http://127.0.0.1:8000";
const NUM_USRES: usize = 500;
pub async fn login(data: &LoginUser) -> Result<Response, reqwest::Error> {
let client = reqwest::Client::new();
let url = format!("{}/login", BASEURL);
client.post(&url).json(data).send().await
}
#[tokio::main]
async fn main() {
for _ in 0..NUM_USERS {
let login_user: LoginUser = LoginUser::random_gen();
login(login_user).await;
}
}