OpenBB-finance/OpenBB · error · OpenBBError
Failed to fetch data for port {port_code}: {e} -> {e.args}
Error message
Failed to fetch data for port {port_code}: {e} -> {e.args} What it means
Wrapped error from fetch_port_data: the per-port async call get_daily_port_activity_data(port_code, start, end) raised an exception (HTTP failure, timeout, malformed response, rate limit) for that specific port. The message includes the port_code and the original exception plus its args so the root cause is visible. Only the first failing task's error surfaces this way; others may be aggregated by the gather loop.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/models/port_volume.py:436
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]
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."
)View on GitHub (pinned to 3e071fcc2c)
Solutions
- Retry the request — the failure is usually transient; start with the same port_codes after a short backoff.
- Reduce the port list (split into smaller batches) to lower the chance of one failure aborting the whole gather.
- Inspect e.args in the caught error to identify rate-limit/timeout vs. data issues; add delays between batches if rate-limited.
Example fix
# before
res = await obb.economy.port_volume(provider='imf', port_code='port1114,portgbr023')
# after (per-port retry with backoff)
for attempt in range(3):
try:
res = await obb.economy.port_volume(provider='imf', port_code='port1114,portgbr023')
break
except OpenBBError as e:
if attempt == 2 or 'Failed to fetch data for port' not in str(e):
raise
await asyncio.sleep(2 ** attempt) Defensive patterns
Strategy: retry
Try / catch
import asyncio
from openbb_core.provider.abstract.errors import OpenBBError
async def fetch_with_retry(ports, attempts=3):
for i in range(attempts):
try:
return await obb.economy.port_volume(provider='imf', port_code=ports)
except OpenBBError as e:
if i == attempts - 1 or 'Failed to fetch data for port' not in str(e):
raise
await asyncio.sleep(2 ** i) Prevention
- Batch port codes (e.g. 5-10 per call) so one failure costs little.
- Treat 'Failed to fetch data for port <id>' as transient first — inspect e.args for status text.
- Add jittered backoff in scheduled jobs hitting the IMF API.
When it happens
Trigger: IMF API transient 5xx or timeout while fetching daily activity for one port in a multi-port request; rate limiting when many ports are requested concurrently; network outage mid-batch.
Common situations: Batch jobs requesting dozens of port_codes at once; flaky networks; IMF API maintenance windows; running behind proxies that intermittently drop long-lived connections.
Related errors
- Error fetching port data: {result} -> {result.args[0]}
- start_date must be after 2019-01-01 for IMF Port Volume data
- Expected values as valid portIDs, got None instead.
- No data found for the specified port(s). {port_codes} Ensure
- Unexpected response format when fetching constraints {datafl
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/279c79bfd9ef8770.
Report an issue: GitHub.