OpenBB-finance/OpenBB · error · OpenBBError

{e}

Error message

{e}

What it means

Outer catch-all in the port_info fetcher: any exception escaping the fetch body (non-200 handled above, plus JSON decode errors, KeyErrors on unexpected payload shape like sorting when 'attributes'/'vessel_count_total' is missing, TLS/DNS failures) is re-raised as OpenBBError with the original preserved as `__cause__`. The message is the inner exception's str.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/models/port_info.py:275

                            async with await session.get(url) as response:
                                if response.status != 200:
                                    raise OpenBBError(
                                        f"Failed to fetch data: {response.status}"
                                    )

                                data = await response.json()
                                if "features" in data:
                                    output.extend(data["features"])

            return sorted(
                output,
                key=lambda x: x["attributes"]["vessel_count_total"],
                reverse=True,
            )

        except Exception as e:
            raise OpenBBError(e) from e

    @staticmethod
    def transform_data(
        query: ImfPortInfoQueryParams,
        data: list,
        **kwargs: Any,
    ) -> list[ImfPortInfoData]:
        """Transform the raw data into a list of ImfPortInfoData."""
        results: list[ImfPortInfoData] = []

        if query.country:
            results.extend(
                [
                    ImfPortInfoData(**d["attributes"])
                    for d in sorted(
                        data,
                        key=lambda x: x["attributes"]["vessel_count_total"],
                        reverse=True,

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Inspect `e.__cause__` — a KeyError points to a schema change (update the provider), a ClientError points to network.
  2. Retry on network-type causes.
  3. Upgrade openbb_imf if the underlying ArcGIS schema changed.
  4. Verify egress/proxy settings for services9.arcgis.com.
Defensive patterns

Strategy: try-catch

Try / catch

except OpenBBError as e:
    cause = e.__cause__
    if isinstance(cause, KeyError):
        log.error('PortWatch schema changed: %s', cause)  # update provider
    elif isinstance(cause, (TimeoutError, ConnectionError)):
        await asyncio.sleep(5)
        ports = await obb.economy.imf.port_info()
    else:
        raise

Prevention

When it happens

Trigger: Sorting the features raises KeyError when a record lacks `attributes.vessel_count_total`; `response.json()` fails on truncated HTML error pages; DNS/TLS errors to services9.arcgis.com.

Common situations: PortWatch schema changes removing/renaming vessel_count_total; captive portals or proxies returning HTML; intermittent network conditions.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/d80978f9875bad3b. Report an issue: GitHub.