[Twisted-Python] Trapping exceptions in Deferred
Louis D. Burr
ldanielburr at me.com
Tue May 12 09:33:06 MDT 2015
Hi Mashiat,
> On May 12, 2015, at 9:53 AM, Mashiat Sarker Shakkhar <mashiat.sarker at gmail.com> wrote:
>
> Hi
>
> If I want to trap a certain type of exception in a deferred call, how do I specify it? For example, I see a failure like this:
>
> [HTTP11ClientProtocol (TLSMemoryBIOProtocol),client] [<twisted.python.failure.Failure <class 'OpenSSL.SSL.Error'>>]
> [HTTP11ClientProtocol (TLSMemoryBIOProtocol),client] Traceback (most recent call last):
> [HTTP11ClientProtocol (TLSMemoryBIOProtocol),client] Failure: twisted.web._newclient.ResponseNeverReceived: [<twisted.python.
> failure.Failure <class 'OpenSSL.SSL.Error'>>]
>
> I want to trap all such failures. I tried `failure.trap(twisted.web._newclient.ResponseNeverReceived)` but looks like that did not work. My deferred callback looks like this:
>
> from twisted.internet.error import TimeoutError
> from twisted.web._newclient import ResponseNeverReceived
> def log_ignore_network_errors(failure):
> print failure.getErrorMessage()
> failure.printTraceback()
> failure.trap(TimeoutError, ResponseNeverReceived)
>
> Apparently this does not catch all such errors. What am I doing wrong here?
>
This code sample does not indicate that you have actually assigned log_ignore_network_errors as an errback on a Deferred anywhere. If you can provide a working code example that demonstrates your issue, it will be easier to help you :)
L. Daniel Burr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20150512/2d5cb109/attachment-0002.html>
More information about the Twisted-Python
mailing list