当前位置: 首页>>代码示例>>Python>>正文


Python error.TCPTimedOutError方法代码示例

本文整理汇总了Python中twisted.internet.error.TCPTimedOutError方法的典型用法代码示例。如果您正苦于以下问题:Python error.TCPTimedOutError方法的具体用法?Python error.TCPTimedOutError怎么用?Python error.TCPTimedOutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.TCPTimedOutError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def errback_httpbin(self, failure):
		# log all failures
		self.logger.error(repr(failure))

		# in case you want to do something special for some errors,
		# you may need the failure's type:
		if failure.check(HttpError):
			# these exceptions come from HttpError spider middleware
			# you can get the non-200 response
			response = failure.value.response
			self.logger.error('HttpError on %s', response.url)

		elif failure.check(DNSLookupError):
			# this is the original request
			request = failure.request
			self.logger.error('DNSLookupError on %s', request.url)

		elif failure.check(TimeoutError, TCPTimedOutError):
			request = failure.request
			self.logger.error('TimeoutError on %s', request.url) 
开发者ID:czs0x55aa,项目名称:video_url_crawler_demo,代码行数:22,代码来源:aiqiyi_spider.py

示例2: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def errback_httpbin(self, failure):
        # log all failures
        self.logger.error(repr(failure))

        # in case you want to do something special for some errors,
        # you may need the failure's type:

        if failure.check(HttpError):
            print("HttpError出错了")
            # these exceptions come from HttpError spider middleware
            # you can get the non-200 response
            response = failure.value.response
            self.logger.error('HttpError on %s', response.url)

        elif failure.check(DNSLookupError):
            # this is the original request
            request = failure.request
            self.logger.error('DNSLookupError on %s', request.url)

        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            self.logger.error('TimeoutError on %s', request.url) 
开发者ID:xugongli,项目名称:poi_spider,代码行数:24,代码来源:test_errorback.py

示例3: process_exception

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def process_exception(self, request, exception, spider):
        if spider.name == 'exceptionSpider' and isinstance(exception, TCPTimedOutError):
            self.remove_borken_proxy(request.meta['proxy'])
            return request.copy() 
开发者ID:kingname,项目名称:SourceCodeOfBook,代码行数:6,代码来源:middlewares.py

示例4: handleCmdConnectFailure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def handleCmdConnectFailure(self, failure):
        log.error("CMD CONNECT: %s" % failure.getErrorMessage())

        # Map common twisted errors to SOCKS error codes
        if failure.type == error.NoRouteError:
            self.sendReply(SOCKSv5Reply.NetworkUnreachable)
        elif failure.type == error.ConnectionRefusedError:
            self.sendReply(SOCKSv5Reply.ConnectionRefused)
        elif failure.type == error.TCPTimedOutError or failure.type == error.TimeoutError:
            self.sendReply(SOCKSv5Reply.TTLExpired)
        elif failure.type == error.UnsupportedAddressFamily:
            self.sendReply(SOCKSv5Reply.AddressTypeNotSupported)
        elif failure.type == error.ConnectError:
            # Twisted doesn't have a exception defined for EHOSTUNREACH,
            # so the failure is a ConnectError.  Try to catch this case
            # and send a better reply, but fall back to a GeneralFailure.
            reply = SOCKSv5Reply.GeneralFailure
            try:
                import errno
                if hasattr(errno, "EHOSTUNREACH"):
                    if failure.value.osError == errno.EHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
                if hasattr(errno, "WSAEHOSTUNREACH"):
                    if failure.value.osError == errno.WSAEHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
            except Exception:
                pass
            self.sendReply(reply)
        else:
            self.sendReply(SOCKSv5Reply.GeneralFailure)

        failure.trap(error.NoRouteError, error.ConnectionRefusedError,
                     error.TCPTimedOutError, error.TimeoutError,
                     error.UnsupportedAddressFamily, error.ConnectError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:socks5.py

示例5: test_errno

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def test_errno(self):
        """
        L{error.getConnectError} converts based on errno for C{socket.error}.
        """
        self.assertErrnoException(errno.ENETUNREACH, error.NoRouteError)
        self.assertErrnoException(errno.ECONNREFUSED, error.ConnectionRefusedError)
        self.assertErrnoException(errno.ETIMEDOUT, error.TCPTimedOutError)
        if platformType == "win32":
            self.assertErrnoException(errno.WSAECONNREFUSED, error.ConnectionRefusedError)
            self.assertErrnoException(errno.WSAENETUNREACH, error.NoRouteError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_error.py

示例6: errorback

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def errorback(self, failure):
        loader = ItemLoader(item=Collector())
        if failure.check(HttpError):
            response = failure.value.response
            loader.add_value("dl_slot", response.request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", response.status)
            loader.add_value("ID", response.request.meta["ID"])
            yield loader.load_item()
        elif failure.check(DNSLookupError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "DNS")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item() 
        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "Timeout")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item()
        else:
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "other")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item()


##################################################################
# MAIN PARSE
################################################################## 
开发者ID:datawizard1337,项目名称:ARGUS,代码行数:49,代码来源:textspider.py

示例7: errorback

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def errorback(self, failure):
        loader = ItemLoader(item=LinkCollector())
        if failure.check(HttpError):
            response = failure.value.response
            loader.add_value("dl_slot", response.request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", response.status)
            loader.add_value("ID", response.request.meta["ID"])
            loader.add_value("links", "")
            loader.add_value("alias", "")
            yield loader.load_item()
        elif failure.check(DNSLookupError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "DNS")
            loader.add_value("ID", request.meta["ID"])
            loader.add_value("links", "")
            loader.add_value("alias", "")
            yield loader.load_item() 
        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "Timeout")
            loader.add_value("ID", request.meta["ID"])
            loader.add_value("links", "")
            loader.add_value("alias", "")
            yield loader.load_item()
        else:
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("error", "other")
            loader.add_value("ID", request.meta["ID"])
            loader.add_value("links", "")
            loader.add_value("alias", "")
            yield loader.load_item()


##################################################################
# MAIN PARSE
################################################################## 
开发者ID:datawizard1337,项目名称:ARGUS,代码行数:57,代码来源:linkspider.py

示例8: errorback

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TCPTimedOutError [as 别名]
def errorback(self, failure):
        loader = ItemLoader(item=Collector())
        if failure.check(HttpError):
            response = failure.value.response
            loader.add_value("dl_slot", response.request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("title", "")
            loader.add_value("description", "")
            loader.add_value("keywords", "")
            loader.add_value("error", response.status)
            loader.add_value("ID", response.request.meta["ID"])
            yield loader.load_item()
        elif failure.check(DNSLookupError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("title", "")
            loader.add_value("description", "")
            loader.add_value("keywords", "")
            loader.add_value("error", "DNS")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item() 
        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("title", "")
            loader.add_value("description", "")
            loader.add_value("keywords", "")
            loader.add_value("error", "Timeout")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item()
        else:
            request = failure.request
            loader.add_value("dl_slot", request.meta.get('download_slot'))
            loader.add_value("start_page", "")
            loader.add_value("scraped_urls", "")
            loader.add_value("redirect", [None])
            loader.add_value("scraped_text", "")
            loader.add_value("title", "")
            loader.add_value("description", "")
            loader.add_value("keywords", "")
            loader.add_value("error", "other")
            loader.add_value("ID", request.meta["ID"])
            yield loader.load_item()


##################################################################
# MAIN PARSE
################################################################## 
开发者ID:datawizard1337,项目名称:ARGUS,代码行数:61,代码来源:textspider.py


注:本文中的twisted.internet.error.TCPTimedOutError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。