You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
urllib.request: opener not resetting content-length #60668
The first opener.open adds data and several headers to request, including content-length. The second changes the data but not the content-length. The docs do not say anything about this either way.
This is special case for more "general" problem. When request is executed with HTTP client and data is not None, it calculates content length and adds special header to request. Then one can change request.data attribute value, but header "Content-length" is not changed in this case.
Patch is attached.
I implemented request.data as property and added method "remove_header" to deal problem. Test cases are also provided.
changeset: 89857:ad0c75b7bd7d
tag: tip
parent: 89855:9120196b3114
parent: 89856:68335b8afb1f
user: Victor Stinner <victor.stinner@gmail.com>
date: Wed Mar 19 17:34:12 2014 +0100
description:
(Merge 3.4) Skip test_urllib2.test_issue16464() is the ssl module is missing
changeset: 89856:68335b8afb1f
branch: 3.4
parent: 89852:c44258b4b7a4
user: Victor Stinner <victor.stinner@gmail.com>
date: Wed Mar 19 17:31:20 2014 +0100
files: Lib/test/test_urllib2.py
description:
Skip test_urllib2.test_issue16464() is the ssl module is missing
Activity
terryjreedy commentedon Nov 13, 2012
Code based on python-list post by a do-not-wish-to-register urllib user.
The first opener.open adds data and several headers to request, including content-length. The second changes the data but not the content-length. The docs do not say anything about this either way.
kachayev commentedon Nov 17, 2012
This is special case for more "general" problem. When request is executed with HTTP client and data is not None, it calculates content length and adds special header to request. Then one can change request.data attribute value, but header "Content-length" is not changed in this case.
Patch is attached.
I implemented request.data as property and added method "remove_header" to deal problem. Test cases are also provided.
asvetlov commentedon Nov 22, 2012
I'm agree with solution, see my comments in review for the patch.
asvetlov commentedon Nov 22, 2012
Perhaps it's a bit new behavior and should be applied to 3.4 only.
kachayev commentedon Nov 22, 2012
Fixed patch is attached.
Documentation is updated.
python-dev commentedon Nov 27, 2012
New changeset 618ea5612e83 by Andrew Svetlov in branch 'default':
Issue bpo-16464: reset Request's Content-Length header on .data change.
http://hg.python.org/cpython/rev/618ea5612e83
asvetlov commentedon Nov 27, 2012
Pushed.
Thanks, Alexey.
python-dev commentedon Mar 20, 2013
New changeset b1579eb4e1bc by R David Murray in branch 'default':
bpo-17485: Delete the Content-Length header if the data attribute is deleted.
http://hg.python.org/cpython/rev/b1579eb4e1bc
python-dev commentedon Mar 10, 2014
New changeset e6d862886e5c by R David Murray in branch 'default':
whatsnew: urllib Request objects are now reusable.
http://hg.python.org/cpython/rev/e6d862886e5c
vstinner commentedon Mar 19, 2014
changeset: 89857:ad0c75b7bd7d
tag: tip
parent: 89855:9120196b3114
parent: 89856:68335b8afb1f
user: Victor Stinner <victor.stinner@gmail.com>
date: Wed Mar 19 17:34:12 2014 +0100
description:
(Merge 3.4) Skip test_urllib2.test_issue16464() is the ssl module is missing
changeset: 89856:68335b8afb1f
branch: 3.4
parent: 89852:c44258b4b7a4
user: Victor Stinner <victor.stinner@gmail.com>
date: Wed Mar 19 17:31:20 2014 +0100
files: Lib/test/test_urllib2.py
description:
Skip test_urllib2.test_issue16464() is the ssl module is missing