本文整理匯總了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)
示例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)
示例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()
示例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)
示例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)
示例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
##################################################################
示例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
##################################################################
示例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
##################################################################