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.retrieve's reporthook called with non-helpful value #43374
Seems like the 'reporthook', when provided to the
'retrieve' function of urllib will be called with
(blocknumber, blocksize, totalsize).
However, the call to read() might return *less* than
'blocksize' bytes (I believe), so it should imho be
called with len(block) as the second argument instead.
Or maybe add a fourth argument 'readbytes'.
Attached patch adds new argument: progresshook - it will be passed two
arguments: count of downloaded bytes and total file size (or -1 if it's
not available).
Introducing new argument instead of modifying reporthook maintains
backwards compatibility, also allows removal of reporthook at one point
in the future.
We will close this as wont do. There is no right answer for the "fix" here; we are dealing with the original API design, and changing the behavior of reporthook's argument is not bring any significant benefit.
Activity
sidnei commentedon May 18, 2006
Seems like the 'reporthook', when provided to the
'retrieve' function of urllib will be called with
(blocknumber, blocksize, totalsize).
However, the call to read() might return *less* than
'blocksize' bytes (I believe), so it should imho be
called with len(block) as the second argument instead.
Or maybe add a fourth argument 'readbytes'.
nelchael commentedon Dec 7, 2008
Attached patch adds new argument: progresshook - it will be passed two
arguments: count of downloaded bytes and total file size (or -1 if it's
not available).
Introducing new argument instead of modifying reporthook maintains
backwards compatibility, also allows removal of reporthook at one point
in the future.
This patch is against r30 SVN tag.
devdanzin commentedon Feb 12, 2009
Patch has docs, tests needed.
zanella commentedon Apr 24, 2011
Simple (lazy) test case added.
It just replicates one test case of reporthook to work with progresshook.
The testcases assume the hard-coded value of blocksize on urllib, maybe it should become a public property.
Also commented on diff: http://bugs.python.org/review/1490929/show
4kir4 commentedon Nov 5, 2012
Related bpo-16409
iritkatriel commentedon Oct 25, 2020
The code in urllib is different now but I see that a test very similar to the one in the patch exists, so was this fixed?
cpython/Lib/test/test_urllib.py
Line 813 in e68c678
orsenthil commentedon Oct 26, 2020
Irit, not really. This is adding another hook called "progress hook" in addition to the "report hook". We need to evaluate if this is really required.
15 remaining items
Revert "pythonGH-43374: Fix urlretrieve reporthook to report actual b…
orsenthil commentedon Jan 12, 2026
We will close this as wont do. There is no right answer for the "fix" here; we are dealing with the original API design, and changing the behavior of reporthook's argument is not bring any significant benefit.
The existing behavior as established in https://hg.python.org/cpython/rev/8c48eb0239ca seems good to me, and we can close this issue as wont do.
GH-43374: Revert "GH-43374: Fix urlretrieve reporthook to report actu…
orsenthil commentedon Jan 12, 2026
Let's close this one. Open issue resulted in some confusion regarding a 'fix'
#142653 (comment)
I don't think any confusion is worth for this issue at the moment.
hugovk commentedon Jan 12, 2026
(Re-closing as "not planned")
pythonGH-43374: Fix urlretrieve reporthook to report actual bytes read (
pythonGH-43374: Fix urlretrieve reporthook to report actual bytes read (
pythonGH-43374: Revert "pythonGH-43374: Fix urlretrieve reporthook to…