22 lines
		
	
	
		
			719 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			719 B
		
	
	
	
		
			Python
		
	
	
	
| import requests
 | |
| 
 | |
| def fetch_image():
 | |
|     api_url = "https://st2.depositphotos.com/22162388/50231/i/450/depositphotos_502316854-stock-photo-api-application-programming-interface-function.jpg"  # Replace this with the actual API URL
 | |
|     
 | |
|     try:
 | |
|         response = requests.get(api_url)
 | |
|         
 | |
|         if response.status_code == 200:
 | |
|             image_data = response.content
 | |
|             
 | |
|             with open("image.png", "wb") as file:
 | |
|                 file.write(image_data)
 | |
|                 
 | |
|             print("Image saved successfully as image.png")
 | |
|         else:
 | |
|             print(f"Failed to fetch image: {response.status_code}")
 | |
|     except Exception as e:
 | |
|         print(f"An error occurred: {e}")
 | |
| 
 | |
| fetch_image()
 |