try: with open(filename, 'wb') as file: file.write(response.content) print(f"Image saved as {filename}") except Exception as err: print(f"Error saving image: {err}")