HTTPError... read the response body?

Stuart Davenport stuart.davenport at gmail.com
Tue Mar 3 04:22:48 EST 2009


On Mar 2, 11:50 pm, Wojtek Walczak <gmin... at bzt.bzt> wrote:
> On Mon, 2 Mar 2009 14:29:12 -0800 (PST), Stuart Davenport wrote:
>
> Hi,
>
> > I am trying to connect to a web service but I am getting HTTP 400, I
> > am not too concerned about the HTTP error - but what I'd like to know
> > if there is anyway I can read the response body in the HTTP 400 or 500
> > case? Does the HTTPError allow this? or the urllib2 in anyway?
>
> HTTP error 400 means 'bad request', so it's almost certainly
> your mistake.
>
> >                         #url, body, headers
> >                         rq = urllib2.Request(args[1], args[3], headers)
>
> Is args[1] a valid URL? And are you sure that you want to send
> something to the web serwer? By specifying the second argument
> (args[3]) you're asking python to send HTTP "POST" request,
> not "GET".
>
> --
> Regards,
> Wojtek Walczak,http://tosh.pl/gminick/

Hi Wojtek,

Yes, the args[1] is a valid url (I've printed it out to check) and
thats correct, I do want to initiate a POST request by passing over
the SOAP Envelope in the request. All I'd like to know if there is
anyway to read the body of an HTTP Error, so for instance, if I were
to recieve a 404 - I'd like to see the content that the server returns
with a 404 error.



More information about the Python-list mailing list