CaptureKit

Comprobar la respuesta

Asegúrate de que la respuesta es una imagen antes de guardarla.

El encabezado Content-Type indica el formato del archivo: aquí image/png (application/pdf con format=pdf). Un error llega en JSON, con un estado HTTP de error.

Este código continúa el script de Solicita una captura de pantalla.

content_type = response.headers.get("content-type", "")
if not content_type.startswith("image/"):
    raise SystemExit(f"Expected an image, got {content_type}: {response.text}")
print(f"Content type: {content_type}")