代码之家  ›  专栏  ›  技术社区  ›  Asym

Scrapy-设置TCP连接超时

  •  2
  • Asym  · 技术社区  · 7 年前

    我正试图通过Scrapy刮一个网站。然而,该网站有时速度非常慢,在浏览器中第一次请求时需要大约15-20秒才能做出响应。无论如何,有时,当我尝试使用Scrapy爬行网站时,我会不断收到TCP超时错误。即使网站在我的浏览器上打开得很好。以下是信息:

    2017-09-05 17:34:41 [scrapy.downloadermiddlewares.retry] DEBUG: Gave up retrying <GET http://www.hosane.com/result/spec
    ialList> (failed 16 times): TCP connection timed out: 10060: A connection attempt failed because the connected party di
    d not properly respond after a period of time, or established connection failed because connected host has failed to re
    spond..
    

    USER_AGENT 测试设置。 我不认为 DOWNLOAD_TIMEOUT

    1 回复  |  直到 7 年前
        1
  •  10
  •   paul trmbrth    7 年前

    A. TCP connection timed out 可能发生在指定的刮痕之前 DOWNLOAD_TIMEOUT SYN 数据包重传。

    默认情况下,在我的Linux机器上,我有6次重新传输:

    cat /proc/sys/net/ipv4/tcp_syn_retries
    6
    

    0 + 1 + 2 + 4 + 8 + 16 + 32 (+64) = 127 seconds 在收到 twisted.internet.error.TCPTimedOutError: TCP connection timed out: 110: Connection timed out.

    /proc/sys/net/ipv4/tcp_syn_retries 例如,我可以验证我是否收到了以下信息:

    User timeout caused connection failure: Getting http://www.hosane.com/result/specialList took longer than 180.0 seconds.
    

    0+1+2+4+8+16+32+64+128(+256) > 180 .

    10060: A connection attempt failed... 似乎是Windows套接字错误代码。如果您想将TCP连接超时至少更改为 ,您需要更改TCP SYN公司 重试计数。(我不知道如何在你的系统上做到这一点,但谷歌是你的朋友。)