我是靠谱客的博主 文艺小伙,这篇文章主要介绍scrapy报错解决[twisted.internet.error.TimeoutError: User timeout caused connection failure:],现在分享给大家,希望可以做个参考。
在scrapy中遇到报错:twisted.internet.error.TimeoutError: User timeout caused connection failure:
一般是设置了DOWNLOAD_TIMEOUT 之后,用了代理ip等等,就会出现这类报错。
解决方法为:
在middleware中,捕获这个报错,并返回request,让他重新请求这个对象
先导入
from twisted.internet.error import TimeoutError
def process_exception(self, request, exception, spider):
# Called when a download handler or a process_request()
# (from other downloader middleware) raises an exception.
# Must either:
# - return None: continue processing this exception
# - return a Response object: stops process_exception() chain
# - return a Request object: stops process_exception() chain
if isinstance(exception,TimeoutError):
return request
最后
以上就是文艺小伙最近收集整理的关于scrapy报错解决[twisted.internet.error.TimeoutError: User timeout caused connection failure:]的全部内容,更多相关scrapy报错解决[twisted.internet.error.TimeoutError:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复