我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用twisted.internet.error.TCPTimedOutError()。
def error_back(self, failure): #request????error_back #???????request????????????????? #???????dns??????? #???????????redis??????? if failure.check(HttpError): #?????200????? response = failure.value.response self.logger.error('[%s] GET [%d]', response.url, response.status) if failure.check(DNSLookupError): #dns???? request = failure.request self.logger.error('[%s] DNSLookupError', request.url) if failure.check(TimeoutError, TCPTimedOutError): #???? request = failure.request self.logger.error('[%s] TimeoutError', request.url)
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)
def process_exception(self, request, exception, spider): #???????????????????request?????? #??????????????? #???????????????????????????????????? if isinstance(exception, DNSLookupError): self.crawler.signals.send_catch_log(dnslookuperror, spider=spider) if isinstance(exception, (TimeoutError, TCPTimedOutError)): self.crawler.signals.send_catch_log(timeouterror, spider=spider) return request
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)