{"record":{"id":"72f2cf1e97880c88","repo":"OpenBB-finance/OpenBB","slug":"an-error-occurred-during-the-http-request-url","errorCode":null,"errorMessage":"An error occurred during the HTTP request: {url} -> {e} -> {res_content}","messagePattern":"An error occurred during the HTTP request: (.+?) -> (.+?) -> (.+?)","errorType":"http","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/query_builder.py","lineNumber":364,"sourceCode":"            self.validate_dimension_constraints(\n                dataflow, start_date=start_date, end_date=end_date, **kwargs\n            )\n\n        url = self.build_url(dataflow, start_date, end_date, limit=limit, **kwargs)\n        headers = {\n            \"Accept\": \"application/xml\",\n            \"Cache-Control\": \"no-cache\",\n            \"User-Agent\": \"Open Data Platform - IMF Data Fetcher\",\n        }\n        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","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/query_builder.py#L346-L382","documentation":"fetch_data raises OpenBBError when requests raises a RequestException while GETting the SDMX XML (network fault or raise_for_status() converting a 4xx/5xx into an exception). The message includes the URL, the exception, and the response body, which usually contains the server's XML error detail.","triggerScenarios":"api.imf.org returning 404/500 for the built URL, TLS/DNS failures, timeouts, or proxy interference; note the request sends a custom User-Agent and Accept: application/xml header.","commonSituations":"Transient IMF API outages, overly aggressive polling triggering 5xx, firewalls stripping custom headers, or URLs built with dimension keys the server rejects.","solutions":["Inspect the trailing res_content: IMF SDMX error XML pinpoints the offending dimension/value.","Retry with backoff for 5xx/timeouts; treat 4xx as a query problem per the body.","Confirm api.imf.org/external/sdmx/3.0 is reachable from your network and proxies pass the custom headers.","If the URL contains wildcards/keys you did not intend, re-check build_url inputs."],"exampleFix":"# before\nurl = qb.build_url('BAD', REF_AREA='XX')  # -> 4xx wrapped as OpenBBError\n\n# after\ntry:\n    df = qb.fetch_data(url)\nexcept OpenBBError as e:\n    time.sleep(2 ** attempt)\n    df = qb.fetch_data(url)  # retry transient 5xx only","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(4):\n    try:\n        df = qb.fetch_data(url)\n        break\n    except OpenBBError as e:\n        if 'HTTP request' not in str(e) or attempt == 3:\n            raise\n        if is_client_error(str(e)):\n            raise  # 4xx: fix the query, do not retry\n        time.sleep(2 ** attempt)","preventionTips":["Send the same headers (custom User-Agent, Accept: application/xml) when reproducing the URL manually.","Rate-limit against api.imf.org and add exponential backoff on 5xx.","Log the response body from the message — IMF's XML error names the exact bad dimension."],"tags":["network","imf","http","sdmx","retry"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}