OpenBB-finance/OpenBB · error · OpenBBError
Expected values as valid portIDs, got None instead.
Error message
Expected values as valid portIDs, got None instead.
What it means
Raised in ImfPortVolumeFetcher.aawindow (the async data step) when the resolved port_codes sequence is falsy — either query.port_code is None/empty, or get_port_ids_by_country(query.country) returned an empty list. It signals that the country->ports lookup produced nothing, so there is no port to query. The message ('got None instead') slightly misleads: an empty list from an unknown country triggers it too.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/models/port_volume.py:423
**kwargs: Any,
) -> list:
"""Extract data from the IMF Port Volume API."""
# pylint: disable=import-outside-toplevel
import asyncio # noqa
from openbb_imf.utils.port_watch_helpers import get_daily_port_activity_data
port_codes = (
get_port_ids_by_country(query.country)
if query.country
else (
query.port_code.split(",")
if isinstance(query.port_code, str)
else query.port_code
)
)
if not port_codes:
raise OpenBBError("Expected values as valid portIDs, got None instead.")
output: list = []
async def fetch_port_data(port_code: str):
"""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]
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Verify the country has PortWatch ports and pass explicit port_codes instead: use the provider's port map / IMF PortWatch explorer to find valid IDs.
- If country-based selection matters, check the return of get_port_ids_by_country(country) before calling and surface a clear error when empty.
- Fall back to the default port (port1114) when no ports resolve.
Example fix
# before
res = await obb.economy.port_volume(provider='imf', country='liechtenstein') # no ports -> empty lookup
# after
from openbb_imf.models.port_volume import get_port_ids_by_country
ports = get_port_ids_by_country('liechtenstein')
if not ports:
raise ValueError(f'No IMF PortWatch ports for this country; pass port_code explicitly.')
res = await obb.economy.port_volume(provider='imf', port_code=','.join(ports)) Defensive patterns
Strategy: validation
Validate before calling
from openbb_imf.models.port_volume import get_port_ids_by_country
ports = get_port_ids_by_country(country) if country else None
if not ports:
ports = ['port1114'] # or raise your own informative error
res = await obb.economy.port_volume(provider='imf', port_code=','.join(ports)) Type guard
def has_resolvable_ports(country: str | None, port_code: str | None) -> bool:
if port_code and port_code.strip():
return True
if country:
from openbb_imf.models.port_volume import get_port_ids_by_country
return bool(get_port_ids_by_country(country))
return False Try / catch
try:
res = await obb.economy.port_volume(provider='imf', country=country)
except OpenBBError as e:
if 'valid portIDs' in str(e):
res = await obb.economy.port_volume(provider='imf', port_code='port1114') Prevention
- Check get_port_ids_by_country(country) is non-empty before relying on country-only queries.
- Prefer explicit port_codes in automated pipelines.
- Note: message says 'None' but an empty list triggers it too.
When it happens
Trigger: Passing country='atlantis' (or a valid country with no PortWatch ports) so get_port_ids_by_country returns []; or constructing ImfPortVolumeQueryParams in a way that leaves port_code falsy after validation.
Common situations: Assuming every country has ports in the PortWatch dataset; passing country names in the wrong format (display name vs snake_case); chained workflows where the country resolution step silently yields [].
Related errors
- start_date must be after 2019-01-01 for IMF Port Volume data
- No valid port_code provided.
- Minimum start_date is 2019-01-01. Got {values['start_date']}
- Failed to fetch data for port {port_code}: {e} -> {e.args}
- No data found for the specified port(s). {port_codes} Ensure
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/b0a9043c258967a1.
Report an issue: GitHub.