if res.ok:
    with open(path, 'wb') as handle:
        for block in res.iter_content(1024):
            if block:
                handle.write(block)
handle.flush()
Maintain updated file cache of web pages in Python?