{"record":{"id":"e336bb953f01f648","repo":"OpenBB-finance/OpenBB","slug":"failed-to-fetch-ports-data-response-status-r","errorCode":null,"errorMessage":"Failed to fetch ports data: {response.status} - {response.reason}","messagePattern":"Failed to fetch ports data: (.+?) - (.+?)","errorType":"http","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py","lineNumber":418,"sourceCode":"        A list of dictionaries, each representing a port with its details.\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    from openbb_core.app.model.abstract.error import OpenBBError\n    from openbb_core.provider.utils.helpers import get_async_requests_session\n\n    url = (\n        \"https://services9.arcgis.com/weJ1QsnbMYJlCHdG/arcgis/rest/services/PortWatch_ports_database/\"\n        + \"FeatureServer/0/query?where=1%3D1&outFields=countrynoaccents,portid,lon,lat,portname,ISO3,continent,fullname\"\n        + \"+&returnGeometry=false&orderByFields=vessel_count_total%20DESC&outSR=&f=json\"\n    )\n    ports: list[dict] = []\n\n    try:\n        async with await get_async_requests_session() as session, await session.get(\n            url\n        ) as response:\n            if response.status != 200:\n                raise OpenBBError(\n                    f\"Failed to fetch ports data: {response.status} - {response.reason}\"\n                )\n            data = await response.json()\n\n            for feature in data.get(\"features\", []):\n                ports.append(feature.get(\"attributes\", {}))\n\n        return ports\n\n    except Exception as e:\n        raise OpenBBError(f\"Error fetching ports data: {e} -> {e.args}\") from e\n\n\ndef get_ports() -> list[dict[str, Any]]:\n    \"\"\"Get the list of all ports synchronously.\"\"\"\n    # pylint: disable=import-outside-toplevel\n    import asyncio\n","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py#L400-L436","documentation":"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.","triggerScenarios":"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.","commonSituations":"ArcGIS Online throttling or maintenance, corporate proxies/firewalls blocking arcgis.com, or a changed FeatureServer path after IMF updates the PortWatch database.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        ports = await get_ports()\n        break\n    except OpenBBError as e:\n        if 'Failed to fetch ports data' not in str(e) or attempt == 2:\n            raise\n        await asyncio.sleep(2 ** attempt)","preventionTips":["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."],"tags":["network","imf","portwatch","arcgis","http-status"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}