0

注意:这个问题是由于我在站点只支持 HTTP 时使用 HTTPS 引起的。如果您遇到此问题,请检查此!


我正在尝试用 Rust 制作一个小型网络爬虫。当我尝试使用 reqwest 库发送 GET 请求时,程序挂起。

我的代码显示了这个问题:

extern crate reqwest;

use reqwest::Client;

fn main() {
    let client = Client::new();

    println!("Checkpoint 1!");
    println!("=> {:?}", client.get("https://eth0.me").send().unwrap().text());
    println!("Checkpoint 2!");
}

在终端中运行:

$ cargo run
  Finished dev [unoptimized + debuginfo] targets in 0.0 secs
  Running `target/debug/crawler`
Checkpoint 1!

似乎请求超时,稍后(我认为是 1 分钟):

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Io(Custom { kind: WouldBlock, error: StringError("timed out") }), url: Some("https://eth0.me/") }', libcore/result.rs:945:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
             at libstd/panicking.rs:537
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:521
   7: rust_begin_unwind
             at libstd/panicking.rs:497
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:71
   9: core::result::unwrap_failed
             at /checkout/src/libcore/macros.rs:23
  10: <core::result::Result<T, E>>::unwrap
             at /checkout/src/libcore/result.rs:782
  11: crawler::main
             at src/main.rs:8
  12: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  13: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:479
  14: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  15: std::rt::lang_start_internal
             at libstd/panicking.rs:458
             at libstd/panic.rs:358
             at libstd/rt.rs:58
  16: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  17: main
  18: __libc_start_main
  19: _start

在 strace 中,它似乎挂在了futex(0x7ff6b0e2105c, FUTEX_WAIT_PRIVATE, 0, {tv_sec=29, tv_nsec=999994794}. 它似乎也有一个缺失)的 ^C 或超时发生时显示。它等于-1 ETIMEDOUT (Connection timed out超时。

4

0 回答 0