Twisted - how to get text for HTTP error responses

exarkun at exarkun at
Sun Aug 9 18:23:34 CEST 2009

On 03:35 pm, koranthala at wrote:
>   I am writing a HTTP client in Twisted. The client contacts the
>server, and any errors in the sent messages will be returned back to
>the client in 400 message. The reason for failure at the server is
>sent as the text in the 400 message. I tried the same using the
>browser, and I can see the error text (the text might be like - 'Item
>X not found in DB').
>   The client is supposed to use this text and calculate the next
>messages to be sent to the server. But, I cannot seem to find a
>mechanism to get the response text from the errback. I went through
>, but I couldnt find a way to do it.
>   Ex:
>I send a data to the server as so
>d = defer.waitForDeferred(getPage(url, method='POST', headers=hdr,
>yield d
>   reply = d.getResult()
>   success(reply)
>except Error, failure:
>   failure(failure)
>Now, inside failure method, I was unable to print the text out - say
>'Item X not found in DB'.
>Is it possible using Twisted? If so, how can it be done?

The Error instance which the local "failure" is bound to in your example 
above has a number of attributes, one of which is "status" which may be 
what you're looking for.  If not, take a look at its other attributes.


More information about the Python-list mailing list