{"record":{"id":"279c79bfd9ef8770","repo":"OpenBB-finance/OpenBB","slug":"failed-to-fetch-data-for-port-port-code-e","errorCode":null,"errorMessage":"Failed to fetch data for port {port_code}: {e} -> {e.args}","messagePattern":"Failed to fetch data for port (.+?): (.+?) -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/models/port_volume.py","lineNumber":436,"sourceCode":"                else query.port_code\n            )\n        )\n\n        if not port_codes:\n            raise OpenBBError(\"Expected values as valid portIDs, got None instead.\")\n\n        output: list = []\n\n        async def fetch_port_data(port_code: str):\n            \"\"\"Fetch data for a single port.\"\"\"\n            try:\n                data = await get_daily_port_activity_data(\n                    port_code, query.start_date, query.end_date\n                )\n                if data:\n                    output.extend(data)\n            except Exception as e:\n                raise OpenBBError(\n                    f\"Failed to fetch data for port {port_code}: {e} -> {e.args}\"\n                ) from e\n\n        tasks = [fetch_port_data(port_code=port_code) for port_code in port_codes]\n\n        tasks_results = await asyncio.gather(*tasks, return_exceptions=True)\n\n        for result in tasks_results:\n            if isinstance(result, Exception):\n                raise OpenBBError(\n                    f\"Error fetching port data: {result} -> {result.args[0]}\"\n                )\n\n        if not output:\n            raise OpenBBError(\n                f\"No data found for the specified port(s). {port_codes}\"\n                \" Ensure the port_code is correct and available in the IMF PortWatch dataset.\"\n            )","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/models/port_volume.py#L418-L454","documentation":"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.","triggerScenarios":"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.","commonSituations":"Batch jobs requesting dozens of port_codes at once; flaky networks; IMF API maintenance windows; running behind proxies that intermittently drop long-lived connections.","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."],"exampleFix":"# before\nres = await obb.economy.port_volume(provider='imf', port_code='port1114,portgbr023')\n\n# after (per-port retry with backoff)\nfor attempt in range(3):\n    try:\n        res = await obb.economy.port_volume(provider='imf', port_code='port1114,portgbr023')\n        break\n    except OpenBBError as e:\n        if attempt == 2 or 'Failed to fetch data for port' not in str(e):\n            raise\n        await asyncio.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import asyncio\nfrom openbb_core.provider.abstract.errors import OpenBBError\n\nasync def fetch_with_retry(ports, attempts=3):\n    for i in range(attempts):\n        try:\n            return await obb.economy.port_volume(provider='imf', port_code=ports)\n        except OpenBBError as e:\n            if i == attempts - 1 or 'Failed to fetch data for port' not in str(e):\n                raise\n            await asyncio.sleep(2 ** i)","preventionTips":["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."],"tags":["network","retry","imf","ports","async","fetcher"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}