OpenBB-finance/OpenBB · error · OpenBBError
Either port_id or country_code must be provided.
Error message
Either port_id or country_code must be provided.
What it means
Input guard at the top of get_daily_port_activity_data: port_id is None and the function has no country_code parameter to fall back on, so it cannot build a query URL and raises OpenBBError wrapping a ValueError. It is purely a caller-contract violation — despite the message mentioning country_code, this code path requires a concrete port id.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py:312
"""Get the daily port activity data for a specific port ID.
Parameters
----------
port_id : str
The port ID for which to fetch daily activity data.
Returns
-------
list
A list of dictionaries, each representing daily activity data for the specified port.
"""
# pylint: disable=import-outside-toplevel
from datetime import datetime # noqa
from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.provider.utils.helpers import get_async_requests_session
if port_id is None:
raise OpenBBError(
ValueError("Either port_id or country_code must be provided.")
)
if start_date is not None and end_date is None:
end_date = datetime.now().strftime("%Y-%m-%d")
if start_date is None and end_date is not None:
start_date = "2019-01-01"
def get_port_url(offset: int):
"""Construct the URL for fetching chokepoint data with offset."""
nonlocal port_id, start_date, end_date
return (
(
DAILY_TRADE_BASE_URL
+ f"where=portid%20%3D%20%27{port_id.upper()}%27&" # type: ignore
+ f"outFields=*&orderByFields=date&returnZ=true&resultOffset={offset}&resultRecordCount=1000"
+ "&maxRecordCountFactor=5&outSR=&f=json"View on GitHub (pinned to 3e071fcc2c)
Solutions
- Resolve a concrete port id first (e.g. via get_port_ids_by_country) and pass that.
- Add a None check at your call site with a clear message instead of relying on the provider's.
- If you need country-wide activity, use the country-level helper, not this function.
Example fix
# before
data = await get_daily_port_activity_data(port_id=None)
# after
if port_id is None:
port_id = get_port_ids_by_country(country_code) # or another resolution step
data = await get_daily_port_activity_data(port_id) Defensive patterns
Strategy: validation
Validate before calling
if not port_id: # None or empty
raise ValueError('port_id is required for per-port activity data') Type guard
def has_port_id(port_id: object) -> bool:
return isinstance(port_id, (str, int)) and bool(str(port_id).strip()) Try / catch
try:
await get_daily_port_activity_data(port_id, start, end)
except OpenBBError as e:
if 'port_id or country_code' in str(e):
raise InvalidInput('Resolve a port id before querying') from e
raise Prevention
- Resolve port ids via get_port_ids_by_country before per-port queries.
- Reject None port ids at your own API boundary with a clearer message.
When it happens
Trigger: Calling get_daily_port_activity_data(None) or with an unset variable; code that assumed country-level aggregation was supported by this function.
Common situations: Optional fields from a UI/dataclass defaulting to None and being passed through; refactors where a get_port_ids_by_country result was expected but never resolved to an actual port id.
Related errors
- Country code is not supported by IMF Port Watch.
- At least one extension type must be selected.
- Incorrect email or password
- Charting is not installed. Please install `openbb-charting`.
- Invalid command : route={route}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/ebef9485f890363e.
Report an issue: GitHub.