0

how do i estimate download progress/time when the file to be downloaded lacks the content-length information? Thanks

Kennedy
  • 2,146
  • 6
  • 31
  • 44
  • To get progress, you need the current size and the total size. If you don't know the total size, it's impossible to know how big the file is unless you download it fully, which would render a progress useless. – Blender Nov 24 '10 at 15:34
  • 3
    `import random; `print 10**10**10**10 * random.uniform()` Repeat at regular intervals to provide the user with updated estimates. – aaronasterling Nov 24 '10 at 15:41
  • You could guess... Most of the time that's what those estimates look like anyway... – FrustratedWithFormsDesigner Nov 24 '10 at 15:41
  • 3
    use MS© progress© bar©: start downloading, show 0% when finished, jump to 100% – Matus Nov 24 '10 at 16:20

1 Answers1

1

You you find yourself in the rather improbable situation that the server won't send you content lengths but accepts byte range requests (and you really really need to know how long it'll take), you can use the code in Python seek on remote file using HTTP and do a binary search to get some notion about the file size. Ask for a range beyond the file size and you'll receive:

HTTPError: HTTP Error 416: Requested Range Not Satisfiable
Community
  • 1
  • 1
TryPyPy
  • 6,214
  • 5
  • 35
  • 63