Ref : https://github.com/python/cpython/pull/25174

https://github.com/localstack/localstack/blob/5a5edcd9d9ccbd6a56f23d71e3a1131b8c814996/localstack/utils/common.py#L324
"""Downloads file at url to the given path"""
    
    
    s = requests.Session()
    
    
    r = s.get(url, stream=True, verify=os.getenv('REQUESTS_CA_BUNDLE', verify_ssl))
    
    if r.status_code >= 400:
        raise Exception('Failed to download %s, response code %s' % (url, r.status_code))
    total = 0
    try:
        if not os.path.exists(os.path.dirname(path)):
            os.makedirs(os.path.dirname(path))
        LOG.debug('Starting download from %s to %s (%s bytes)' % (url, path, r.headers.get('Content-Length')))
        with open(path, 'wb') as f:
            iter_length = 0
            iter_limit = 1000000  
            for chunk in r.iter_content(DOWNLOAD_CHUNK_SIZE):
                total += len(chunk)
                iter_length += len(chunk)
                if chunk:  
                    f.write(chunk)
                else:
                    LOG.debug('Empty chunk %s (total %s) from %s' % (chunk, total, url))