{"record":{"id":"f9f4f37841e166f8","repo":"OpenBB-finance/OpenBB","slug":"failed-to-parse-xml-response-url-e","errorCode":null,"errorMessage":"Failed to parse XML response: {url} -> {e}","messagePattern":"Failed to parse XML response: (.+?) -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/query_builder.py","lineNumber":374,"sourceCode":"        response = None\n\n        try:\n            response = make_request(url, headers=headers)\n            response.raise_for_status()\n            xml_content = response.text\n        except RequestException as e:\n            res_content = response.text if response else \"\"\n            raise OpenBBError(\n                f\"An error occurred during the HTTP request: {url} -> {e} -> {res_content}\"\n            ) from e\n\n        # Parse XML\n        try:\n            import defusedxml.ElementTree as DefusedET\n\n            root = DefusedET.fromstring(xml_content)\n        except Exception as e:  # pylint: disable=broad-except\n            raise OpenBBError(f\"Failed to parse XML response: {url} -> {e}\") from e\n\n        # Define namespaces used in IMF SDMX responses\n        namespaces = {\n            \"message\": \"http://www.sdmx.org/resources/sdmxml/schemas/v3_0/message\",\n            \"ss\": \"http://www.sdmx.org/resources/sdmxml/schemas/v3_0/data/structurespecific\",\n            \"common\": \"http://www.sdmx.org/resources/sdmxml/schemas/v3_0/common\",\n        }\n\n        # Find all Series elements\n        dataset = root.find(\".//message:DataSet\", namespaces)\n        if dataset is None:\n            # Try without namespace prefix\n            dataset = root.find(\".//DataSet\")\n        if dataset is None:\n            # Try with ss namespace\n            dataset = root.find(\".//ss:DataSet\", namespaces)\n        if dataset is None:\n            raise OpenBBError(","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/query_builder.py#L356-L392","documentation":"After a successful HTTP 200, fetch_data parses the body with defusedxml; any parse failure (malformed XML, empty body, HTML error page served as 200) is wrapped in OpenBBError with the URL and parser exception.","triggerScenarios":"api.imf.org returning HTML/text (WAF block page, maintenance notice) with status 200, truncated responses on interrupted connections, or payloads using an encoding defusedxml cannot decode.","commonSituations":"Corporate proxies rewriting responses, rare server-side serialization bugs, or bot-mitigation pages served to scripted clients.","solutions":["Fetch the URL manually (same headers, incl. User-Agent) and inspect what is actually returned.","Retry — truncation and transient bad payloads usually resolve.","Report to OpenBB if the payload is well-formed XML that this parser rejects, including the URL."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    df = qb.fetch_data(url)\nexcept OpenBBError as e:\n    if 'Failed to parse XML' in str(e):\n        inspect_raw_response(url, headers=imf_headers())  # see what the server really sent\n        time.sleep(5)\n        df = qb.fetch_data(url)\n    else:\n        raise","preventionTips":["Ensure corporate proxies do not rewrite api.imf.org responses.","Retry once on parse failure — truncated/odd 200 payloads are usually transient.","Keep the custom User-Agent header; some WAFs serve HTML to generic agents."],"tags":["parsing","imf","xml","network","proxy"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}