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 crustymonkey
Recipients crustymonkey
Date 2012-02-27.22:44:08
SpamBayes Score 0.0072080605
Marked as misclassified No
Message-id <1330382649.62.0.524230876085.issue14144@psf.upfronthosting.co.za>
In-reply-to
Content
I've noticed that urllib2's HTTPRedirectHandler does not redirect a POST request with the POST data.  

If you send a POST request to a server with data, the data is dropped when the new Request is made to the new url.  As stated in a comment in the library itself, redirecting a POST request is not strictly RFC compliant, but it's generally supported anyway.  The problem here being that our POST data is not also being redirected.  I ran into this issue when writing a web api wrapper in Python.

I'm submitting a small patch that fixes this issue:


--- /usr/lib/python2.7/urllib2.py	2011-10-04 16:07:28.000000000 -0500
+++ urllib2.py	2012-02-27 16:03:36.000000000 -0600
@@ -551,7 +551,11 @@
             newheaders = dict((k,v) for k,v in req.headers.items()
                               if k.lower() not in ("content-length", "content-type")
                              )
+            data = None
+            if req.has_data():
+                data = req.get_data()
             return Request(newurl,
+                           data=data,
                            headers=newheaders,
                            origin_req_host=req.get_origin_req_host(),
                            unverifiable=True)
History
Date User Action Args
2012-02-27 22:44:09crustymonkeysetrecipients: + crustymonkey
2012-02-27 22:44:09crustymonkeysetmessageid: <1330382649.62.0.524230876085.issue14144@psf.upfronthosting.co.za>
2012-02-27 22:44:09crustymonkeylinkissue14144 messages
2012-02-27 22:44:08crustymonkeycreate