OpenBB-finance/OpenBB · error · OpenBBError
An error occurred during the HTTP request: {url} -> {e} -> {
Error message
An error occurred during the HTTP request: {url} -> {e} -> {res_content} What it means
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.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/query_builder.py:364
self.validate_dimension_constraints(
dataflow, start_date=start_date, end_date=end_date, **kwargs
)
url = self.build_url(dataflow, start_date, end_date, limit=limit, **kwargs)
headers = {
"Accept": "application/xml",
"Cache-Control": "no-cache",
"User-Agent": "Open Data Platform - IMF Data Fetcher",
}
response = None
try:
response = make_request(url, headers=headers)
response.raise_for_status()
xml_content = response.text
except RequestException as e:
res_content = response.text if response else ""
raise OpenBBError(
f"An error occurred during the HTTP request: {url} -> {e} -> {res_content}"
) from e
# Parse XML
try:
import defusedxml.ElementTree as DefusedET
root = DefusedET.fromstring(xml_content)
except Exception as e: # pylint: disable=broad-except
raise OpenBBError(f"Failed to parse XML response: {url} -> {e}") from e
# Define namespaces used in IMF SDMX responses
namespaces = {
"message": "http://www.sdmx.org/resources/sdmxml/schemas/v3_0/message",
"ss": "http://www.sdmx.org/resources/sdmxml/schemas/v3_0/data/structurespecific",
"common": "http://www.sdmx.org/resources/sdmxml/schemas/v3_0/common",
}
View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before
url = qb.build_url('BAD', REF_AREA='XX') # -> 4xx wrapped as OpenBBError
# after
try:
df = qb.fetch_data(url)
except OpenBBError as e:
time.sleep(2 ** attempt)
df = qb.fetch_data(url) # retry transient 5xx only Defensive patterns
Strategy: retry
Try / catch
for attempt in range(4):
try:
df = qb.fetch_data(url)
break
except OpenBBError as e:
if 'HTTP request' not in str(e) or attempt == 3:
raise
if is_client_error(str(e)):
raise # 4xx: fix the query, do not retry
time.sleep(2 ** attempt) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Transient IMF API outages, overly aggressive polling triggering 5xx, firewalls stripping custom headers, or URLs built with dimension keys the server rejects.
Related errors
- Unexpected response format when fetching constraints {datafl
- An error occurred while fetching constraints {dataflow_id}:
- Failed to fetch data for port {port_code}: {e} -> {e.args}
- Error fetching port data: {result} -> {result.args[0]}
- Please install polars: `pip install polars pyarrow` to use
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/72f2cf1e97880c88.
Report an issue: GitHub.