Reqwest Crate w/ Actix-Web (No Reactor Running; Tokio Runtime Error)

I'm trying to use the reqwest crate to perform some HTTP get requests for conversion tracking on my website but I keep getting the following error: thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'

Below is the referred code made for testing purposes:

#[actix_rt::main]
async fn main() -> std::io::Result<()>
{
    reqwest::get("https://google.com").await.ok();
    let server = SharedChatServer::default();

    HttpServer::new(move ||
    {
        App::new()
        .data(server.clone())
        .app_data
        (
            WsConfig::new()
            .disable_heartbeat()
        )
        .route("/eventMap", web::post().to(event_map))
        .route("/communities", web::post().to(communities))
        .route("/mainPage", web::post().to(personal_feed))
        .route("/profilePage", web::post().to(profile_page))
        .route("/searchUsers", web::post().to(search_users))
        .route("/registration", web::post().to(registration))
        .route("/credentials", web::post().to(reset_credentials))
        .route("/", web::post().to(authentication))
        .service(chat_route)
        .service(fs::Files::new("/404Error", "./404Error").show_files_listing().index_file("404Error.html"))
        .service(fs::Files::new("/eventMap", "./eventMap").show_files_listing().index_file("eventMap.html"))
        .service(fs::Files::new("/communities/{activity}", "./communities").show_files_listing().index_file("communities.html"))
        .service(fs::Files::new("/communitiesIndex", "./communitiesIndex").show_files_listing().index_file("communitiesIndex.html"))
        .service(fs::Files::new("/mainPage", "./mainPage").show_files_listing().index_file("mainPage.html"))
        .service(fs::Files::new("/notificationFeed/{type}", "./notificationFeed").show_files_listing().index_file("notificationFeed.html"))
        .service(fs::Files::new("/profilePage/{username}", "./profilePage").show_files_listing().index_file("profilePage.html"))
        .service(fs::Files::new("/searchUsers/{name}", "./searchUsers").show_files_listing().index_file("searchUsers.html"))
        .service(fs::Files::new("/registration", "./registration").show_files_listing().index_file("registration.html"))
        .service(fs::Files::new("/credentials", "./forgotCredentials").show_files_listing().index_file("credentials.html"))
        .service(fs::Files::new("/link/{username}", "./logIn").show_files_listing().index_file("logIn.html"))
        .service(fs::Files::new("/", "./logIn").show_files_listing().index_file("logIn.html"))
    })
    .bind("127.0.0.1:8088")?
    .run()
    .await
}

And these are my dependencies:

[dependencies]
actix-web = "3"
actix-rt = "1.0"
actix-files = "0.3"
actix_send_websocket = "0.1.0"
bcrypt = "0.8.2"
chrono = "0.4.19"
lettre = "0.9"
lettre_email = "0.9"
mime = "0.3.13"
rand = "0.7.3"
redis = "0.16.0"
reqwest = "0.11.9"
ron = "0.6.2"
serde = "1.0.115"

Any idea as to what's wrong and how I can fix this issue?

Tge version of Reqwest that you are using depends on Tokio 1.X, while Actix-web 3.x runs on Tokio 0.x.

You need to either use an older version of Reqwest or use Actix-web 4.x

Thanks for the info, do you know the latest version of reqwest that I can use that uses Tokio 0.x?

It's probably 0.10.9

Thanks so much for your help. I just ran the code and it seems to be working :smiley:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.