def download_file(url, data_path='.', filename=None, size=None, chunk_size=4096, verbose=True):
    'Uses stream=True and a reasonable chunk size to be able to download large (GB) files over https'
    if (filename is None):
        filename = dropbox_basename(url)
    file_path = os.path.join(data_path, filename)
    if url.endswith('?dl=0'):
        url = (url[:(- 1)] + '1')
    if verbose:
        tqdm_prog = tqdm
        print('requesting URL: {}'.format(url))
    else:
        tqdm_prog = no_tqdm
    r = requests.get(url, stream=True, allow_redirects=True)
    size = (r.headers.get('Content-Length', None) if (size is None) else size)
    print('remote size: {}'.format(size))
    stat = path_status(file_path)
    print('local size: {}'.format(stat.get('size', None)))
    if ((stat['type'] == 'file') and (stat['size'] == size)):
        r.close()
        return file_path
    print('Downloading to {}'.format(file_path))
    with open(file_path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=chunk_size):
            if chunk:
                f.write(chunk)
    r.close()
    return file_path
Uses stream=True and a reasonable chunk size to be able to download large (GB) files over https
def download_file(url, data_path='.', filename=None, size=None, chunk_size=4096, verbose=True):
    
    if (filename is None):
        filename = dropbox_basename(url)
    file_path = os.path.join(data_path, filename)
    if url.endswith('?dl=0'):
        url = (url[:(- 1)] + '1')
    if verbose:
        tqdm_prog = tqdm
        print('requesting URL: {}'.format(url))
    else:
        tqdm_prog = no_tqdm
    r = requests.get(url, stream=True, allow_redirects=True)
    size = (r.headers.get('Content-Length', None) if (size is None) else size)
    print('remote size: {}'.format(size))
    stat = path_status(file_path)
    print('local size: {}'.format(stat.get('size', None)))
    if ((stat['type'] == 'file') and (stat['size'] == size)):
        r.close()
        return file_path
    print('Downloading to {}'.format(file_path))
    with open(file_path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=chunk_size):
            if chunk:
                f.write(chunk)
    r.close()
    return file_path