TCP connection timed out


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM