[Twisted-Python] How to get original error message in failure object

Pet petshmidt at googlemail.com
Thu Sep 9 08:53:20 EDT 2010

On Thu, Sep 9, 2010 at 2:33 PM,  <exarkun at twistedmatrix.com> wrote:
> On 09:42 am, petshmidt at googlemail.com wrote:
>>if an error occurs in HTTP11ClientProtocol request method
>>(twisted.web._newclient) then error is stored in
>>RequestGenerationFailed Exception and wrapped in Failure object:
>>        def ebRequestWriting(err):
>>            if self._state == 'TRANSMITTING':
>>                self._state = 'GENERATION_FAILED'
>>                self.transport.loseConnection()
>>                 self._finishedRequest.errback(
>>                    Failure(RequestGenerationFailed([err])))
>>            else:
>>                log.err(err, "foo")
>>but if I print detailed traceback of failure in my code it doesn't
>>show all information it contains
>>Original Failure (err in function above):
>>[Failure instance: Traceback: <type 'exceptions.TypeError'>: Data must
>>not be unicode
>>This is detailed traceback, where I don't see the message "Data must
>>not be unicode"
>>*--- Failure #7 (pickled) ---
>>Failure: twisted.web._newclient.RequestGenerationFailed:
>>[<twisted.python.failure.Failure <type 'exceptions.TypeError'>>]
>>*--- End of Failure #7 ---
>>Is there a way to get original error message and where it was raised
>>in Twisted code?
> See the (documented) `reasons` attribute of `RequestGenerationFailed`.

Thanks for hint! RequestGenerationFailed save errors in  `reasons`
attribute, but documentation
doesn't tell how to print reasons. I'm getting just failure object in
my errback.

> Jean-Paul
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list