OpenBB-finance/OpenBB · error · OpenBBError

Error fetching port data: {result} -> {result.args[0]}

Error message

Error fetching port data: {result} -> {result.args[0]}

What it means

Aggregation error after asyncio.gather(..., return_exceptions=True): at least one fetch_port_data task returned an exception object instead of data. The code iterates the results and re-raises the first exception wrapped in OpenBBError, exposing result and result.args[0]. It is the outer half of error 584 — the same underlying per-port failure, but surfaced from the gather loop when the inner wrapper itself propagated as the task's exception.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/models/port_volume.py:446

            """Fetch data for a single port."""
            try:
                data = await get_daily_port_activity_data(
                    port_code, query.start_date, query.end_date
                )
                if data:
                    output.extend(data)
            except Exception as e:
                raise OpenBBError(
                    f"Failed to fetch data for port {port_code}: {e} -> {e.args}"
                ) from e

        tasks = [fetch_port_data(port_code=port_code) for port_code in port_codes]

        tasks_results = await asyncio.gather(*tasks, return_exceptions=True)

        for result in tasks_results:
            if isinstance(result, Exception):
                raise OpenBBError(
                    f"Error fetching port data: {result} -> {result.args[0]}"
                )

        if not output:
            raise OpenBBError(
                f"No data found for the specified port(s). {port_codes}"
                " Ensure the port_code is correct and available in the IMF PortWatch dataset."
            )
        return output

    @staticmethod
    def transform_data(
        query: ImfPortVolumeQueryParams,
        data: list,
        **kwargs: Any,
    ) -> list[ImfPortVolumeData]:
        """Transform the raw data into the model."""
        return [

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Retry the whole request, or split port_codes into batches so a single bad port does not discard successful results.
  2. Extract the failing port from the message ('Error fetching port data: Failed to fetch data for port <id>') and retry without it if partial data is acceptable.
  3. Check result.args[0] content: HTTP status text points to server-side issues (retry later), parse errors point to API contract changes (update the provider package).

Example fix

# before
res = await obb.economy.port_volume(provider='imf', port_code=all_ports)

# after (batched, keep successes)
results = []
for batch in chunks(all_ports, 5):
    try:
        results.append(await obb.economy.port_volume(provider='imf', port_code=','.join(batch)))
    except OpenBBError as e:
        print(f'skipping failed batch {batch}: {e}')
Defensive patterns

Strategy: retry

Try / catch

ok, failed = [], []
for batch in chunks(port_codes, 5):
    try:
        ok.append(await obb.economy.port_volume(provider='imf', port_code=','.join(batch)))
    except OpenBBError as e:
        if 'Error fetching port data' in str(e):
            failed.append((batch, str(e)))
        else:
            raise
# proceed with ok, report failed

Prevention

When it happens

Trigger: One or more ports in a multi-port request failing (network, timeout, invalid response) while gather collects exceptions instead of aborting; the first failing result in tasks_results order determines the message.

Common situations: Large multi-port batches where any single port failure kills the entire response; intermittent IMF API errors; scripts that need all-or-nothing semantics but want the offending port identified.

Related errors


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