Fix issue 10817 - Fix urlretrieve function to raise ContentTooShortError
even when reporthook is None. Patch by Jyrki Pulliainen.
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 8ea058f..ca17da5 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1589,9 +1589,9 @@
size = -1
read = 0
blocknum = 0
+ if "content-length" in headers:
+ size = int(headers["Content-Length"])
if reporthook:
- if "content-length" in headers:
- size = int(headers["Content-Length"])
reporthook(blocknum, bs, size)
while 1:
block = fp.read(bs)