import xml.etree.ElementTree as ET def is_valid(resource, file): """Check if the HTTP response is a well-formed XML document.""" with open(file.name, "rb") as f: try: ET.parse(f) return True except ET.ParseError as e: resource["error"] = str(e) return False