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