OpenBB-finance/OpenBB · error · OpenBBError
Failed to fetch ports data: {response.status} - {response.re
Error message
Failed to fetch ports data: {response.status} - {response.reason} What it means
Raised by get_ports (async) when the initial request to the PortWatch ports database FeatureServer returns a status other than 200. The message includes both status and reason from the aiohttp response so the exact HTTP failure is visible.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py:418
A list of dictionaries, each representing a port with its details.
"""
# pylint: disable=import-outside-toplevel
from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.provider.utils.helpers import get_async_requests_session
url = (
"https://services9.arcgis.com/weJ1QsnbMYJlCHdG/arcgis/rest/services/PortWatch_ports_database/"
+ "FeatureServer/0/query?where=1%3D1&outFields=countrynoaccents,portid,lon,lat,portname,ISO3,continent,fullname"
+ "+&returnGeometry=false&orderByFields=vessel_count_total%20DESC&outSR=&f=json"
)
ports: list[dict] = []
try:
async with await get_async_requests_session() as session, await session.get(
url
) as response:
if response.status != 200:
raise OpenBBError(
f"Failed to fetch ports data: {response.status} - {response.reason}"
)
data = await response.json()
for feature in data.get("features", []):
ports.append(feature.get("attributes", {}))
return ports
except Exception as e:
raise OpenBBError(f"Error fetching ports data: {e} -> {e.args}") from e
def get_ports() -> list[dict[str, Any]]:
"""Get the list of all ports synchronously."""
# pylint: disable=import-outside-toplevel
import asyncio
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Retry after a short wait; 429/503 from ArcGIS are usually transient.
- Verify the FeatureServer URL is reachable: curl 'https://services9.arcgis.com/weJ1QsnbMYJlCHdG/arcgis/rest/services/PortWatch_ports_database/FeatureServer/0/query?where=1%3D1&f=json'.
- Check proxy/firewall settings if the request never leaves the network.
- Upgrade openbb-imf if IMF moved the ports database to a new endpoint.
Defensive patterns
Strategy: retry
Try / catch
for attempt in range(3):
try:
ports = await get_ports()
break
except OpenBBError as e:
if 'Failed to fetch ports data' not in str(e) or attempt == 2:
raise
await asyncio.sleep(2 ** attempt) Prevention
- Cache the ports lookup table locally; it is a slow-changing reference dataset.
- Pre-flight the FeatureServer URL once at startup to fail fast with a clear diagnosis.
- Throttle concurrent PortWatch calls to avoid ArcGIS 429s.
When it happens
Trigger: Any PortWatch endpoint that needs the ports lookup table (mapping port names/IDs to coordinates) when the hardcoded services9.arcgis.com FeatureServer URL responds with 403/429/5xx or is temporarily down.
Common situations: ArcGIS Online throttling or maintenance, corporate proxies/firewalls blocking arcgis.com, or a changed FeatureServer path after IMF updates the PortWatch database.
Related errors
- Failed to fetch data: {response.status}
- Failed to fetch data: {response.status} -> {response.reason}
- Failed to fetch data: {response.status}
- No data found in the response.
- {e}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/e336bb953f01f648.
Report an issue: GitHub.