Making urllib2's POST 302 handle same as Perl LWP's behaviour

2010-12-29 Thread Karra
I am doing a POST to a webserver and get a 302 Found response
(redirect). urllib2's default behaviour is to do a GET on the new url
from the Location: URI in the 302 response.

This is different from what I have found with LWP::UserAgent-
>request() in perl. After much searching I understand there is a view
that automatic redirection for a 302 in response to a POST is not in
conformance to the relevant RFCs. Therefore, I believe urllib2's
behaviour appears to be non-conformant (as, I believe are many
browsers).

Now, regardless of what is the "correct" approach to handling the 302,
there is some information in the returned html of the 302 which I am
losing because of the subsequent GET. I tried to raise a HTTPError
from redirect_request() but that just kills the connection with the
server. I tried returning None, same result.

Can someone point me to how I can get the default LWP:UserAgent
behaviour of handling this scenario using urllib2?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making urllib2's POST 302 handle same as Perl LWP's behaviour

2010-12-29 Thread Karra
On Dec 29, 3:57 pm, Karra  wrote:

> Can someone point me to how I can get the default LWP:UserAgent
> behaviour of handling this scenario using urllib2?

Out of frustration, I decided to give 'mechanize' a try. It came as an
awesome surprise that mechanize implements the exact api of urllib2 -
meaning all I had to do was a query-replace of urllib2 to mechanize,
and lo-and-behold I got what I wanted!

Which is to say, the behaviour of mechanize matches Perl's
LWP::UserAgent as afar as handling of POST redirects go.
-- 
http://mail.python.org/mailman/listinfo/python-list