New submission from Jay Deiman <[email protected]>:
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)
----------
components: Extension Modules
files: urllib2.py.patch
keywords: patch
messages: 154516
nosy: crustymonkey
priority: normal
severity: normal
status: open
title: urllib2 HTTPRedirectHandler not handling POST data in redirect
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file24665/urllib2.py.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14144>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com