[Twisted-Python] Trapping exceptions in Deferred

Mashiat Sarker Shakkhar mashiat.sarker at gmail.com
Tue May 12 08:53:33 MDT 2015


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:

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?

Regards
Shakkhar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20150512/7c4e1a36/attachment.html>


More information about the Twisted-Python mailing list