Python 3 resuma a file download

zljubisic at zljubisic at
Thu Jul 2 22:27:24 CEST 2015

This is my final version which doesn't work. :(
Actually, it works with another file on another server, but doesn't work with mp4 files on this particular server.

I really don't know what to do?


import os
import urllib.request

def Download(rfile, lfile):

    retval = False

    if os.path.isfile(lfile):
        lsize = os.stat(lfile).st_size
        lsize = 0

    req = urllib.request.Request(rfile)

    rfsize = urllib.request.urlopen(req).length

    req.add_header('Range', "bytes={}-".format(lsize))

    response = urllib.request.urlopen(req)

    with open(lfile, 'ab') as out_file:
        while True:
                chunk = * 1024)
                # chunk =
                if not chunk: break

                lfsize = os.stat(lfile).st_size

                 print("{0:.2f}".format(lfsize / rfsize * 100))
            except ConnectionResetError as e:
                print('Exception ConnectionResetError {0}'.format(os.stat(lfile).st_size))
                response = urllib.request.urlopen(req)

    if lfsize == rfsize:
        retval = True

    return retval

while not Download('', 'otv296.mp4'):

More information about the Python-list mailing list