def download_url ( url , filename , headers ) : ensure_dirs ( filename ) response = requests . get ( url , headers = headers , stream = True ) if response . status_code == 200 : with open ( filename , 'wb' ) as f : for chunk in response . iter_content ( 16 * 1024 ) : f . write ( chunk )
how to download a file with python requests
Download a file from url to filename .
def download_url(url, filename, headers):
    """Download a file from `url` to `filename`."""
    ensure_dirs(filename)
    response = requests.get(url, headers=headers, stream=True)
    if response.status_code == 200:
        with open(filename, 'wb') as f:
            for chunk in response.iter_content(16 * 1024):
                f.write(chunk)