TCP连接超时解决办法:10060

# TCP connection timed out: 10060: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
# 原因:你的代理IP过期或者代理IP有问题,导致request.meta[‘proxy’] = random.choice(PROXIES_NEW[http]) 后 request带着这个IP根本无法访问服务器,被挡在外面!
def process_request(self, request, spider):
    proxy = self.get_random_proxy()
    if proxy:
        request.meta["proxy"] = "http://" + proxy

TCP连接超时解决办法:110

解决方法1:
在下载中间件的 process_exception 方法中 ,重新请求一次
from twisted.internet.error import TimeoutError, TCPTimedOutError
def process_exception(self, request, exception, spider):
    if isinstance(exception, TimeoutError):
        return request
    elif isinstance(exception, TCPTimedOutError):
        return request

解决方法2:
通过调整内核参数,提高客户端的链接超时限制。time_wait

解决方法3:
降低并发请求的数量,减少短连接的使用。在 settings.py 中设置一些参数
# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 256
# The initial download delay
AUTOTHROTTLE_START_DELAY = 3
# The maximum download delay to be set in case of high latencies
AUTOTHROTTLE_MAX_DELAY = 30

版权声明:本文为wangshx666原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/wangshx666/p/12850141.html