with open(filepath, 'wb') as file: for chunk in response.iter_content(chunk_size=8192): file.write(chunk)