This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author crocowhile
Recipients ajaksu2, akuchling, crocowhile, jimjjewett, jjlee, kxroberto, orsenthil
Date 2009-08-14.16:41:57
SpamBayes Score 0.008767094
Marked as misclassified No
Message-id <1250268119.12.0.606118382351.issue1424148@psf.upfronthosting.co.za>
In-reply-to
Content
I am not sure where we stand with this issue. It seems to be an old one.
urllib2 still claim (as of python 2.6) the following;

# Strictly (according to RFC 2616), 301 or 302 in response
# to a POST MUST NOT cause a redirection without confirmation
# from the user (of urllib2, in this case).  In practice,
# essentially all clients do redirect in this case, so we
# do the same.
# be conciliant with URIs containing a space

This is just not true, we don't do the same at all. redirect_request
does not pass data along and it even changes the headers to reflect
content-size, thus behaving perfectly in accordance with RFC.

For those who stumbled upon this page looking for a workaround, this is
how to do: create a new class inheriting from HTTPRedirectHandler and
use this one instead:


class AutomaticHTTPRedirectHandler(urllib2.HTTPRedirectHandler):

    def redirect_request(self, req, fp, code, msg, headers, newurl):
        """Return a Request or None in response to a redirect.
        
        The default response in redirect_request claims not to 
        follow directives in RFC 2616 but in fact it does
        This class does not and makes handling 302 with POST
        possible
        """
        m = req.get_method()
        if (code in (301, 302, 303, 307) and m in ("GET", "HEAD")
            or code in (301, 302, 303) and m == "POST"):
            newurl = newurl.replace(' ', '%20')
            return urllib2.Request(newurl,
                           data=req.get_data(),
                           headers=req.headers,
                           origin_req_host=req.get_origin_req_host(),
                           unverifiable=True)
        else:
            raise urllib2.HTTPError(req.get_full_url(), code, msg,
headers, fp)
History
Date User Action Args
2009-08-14 16:41:59crocowhilesetrecipients: + crocowhile, akuchling, jjlee, jimjjewett, orsenthil, kxroberto, ajaksu2
2009-08-14 16:41:59crocowhilesetmessageid: <1250268119.12.0.606118382351.issue1424148@psf.upfronthosting.co.za>
2009-08-14 16:41:57crocowhilelinkissue1424148 messages
2009-08-14 16:41:57crocowhilecreate