{"record":{"id":"bfc6661461798345","repo":"OpenBB-finance/OpenBB","slug":"error-fetching-report-report-id-e","errorCode":null,"errorMessage":"Error fetching report {report_id} -> {e}","messagePattern":"Error fetching report (.+?) -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py","lineNumber":135,"sourceCode":"            template_id = group_data[\"reports\"][report_id][\"templateId\"]\n            break\n\n    if template_id is None:\n        raise OpenBBError(f\"Invalid report ID -> {report_id} was not found.\")\n\n    # Build URLs for both formats\n    html_url = get_report_url(report_id, \"html\")\n    csv_url = get_report_url(report_id, \"csv\")\n    session = await get_async_requests_session()\n\n    try:\n        # Fetch both HTML (for units) and CSV (for data)\n        html_resp = await session.get(html_url)\n        html = await html_resp.text()\n        csv_resp = await session.get(csv_url)\n        csv_text = await csv_resp.text()\n    except ClientError as e:\n        raise OpenBBError(f\"Error fetching report {report_id} -> {e}\") from e\n    finally:\n        await session.close()\n\n    # Check for server error\n    if \"error\" in csv_text.lower():\n        raise OpenBBError(f\"Server error fetching report {report_id} -> {csv_text}\")\n\n    lines = csv_text.replace(\"\\r\", \"\").strip().split(\"\\n\")\n\n    return parse_report(template_id, lines, html)\n\n\ndef _get_commodity_attributes(commodity_code: str) -> list[str]:\n    \"\"\"Fetch valid attribute names for a commodity using the metadata API.\"\"\"\n    # pylint: disable=import-outside-toplevel\n    from openbb_core.provider.utils.helpers import make_request\n\n    try:","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L117-L153","documentation":"Raised when an aiohttp ClientError (connection reset, DNS failure, timeout, TLS error) occurs while fetching the HTML and CSV renderings of a PSD report from apps.fas.usda.gov. The session is closed in finally, and the error is re-raised as OpenBBError with the report id and underlying exception text.","triggerScenarios":"Network interruption or firewall block reaching apps.fas.usda.gov; the server dropping connections during heavy batch scraping of many report ids; transient DNS/TLS failures.","commonSituations":"Bulk-download loops over many report ids that trip server-side connection limits; restricted egress environments (containers, CI) without access to usda.gov.","solutions":["Retry with backoff; ClientError causes are frequently transient.","Add delay/batching between report fetches to avoid the server closing connections.","Verify egress to https://apps.fas.usda.gov (curl) from your environment."],"exampleFix":"# before\nhtml_resp = await session.get(html_url)\n\n# after (bounded retry)\nfor attempt in range(3):\n    try:\n        html_resp = await session.get(html_url)\n        break\n    except ClientError:\n        await asyncio.sleep(2 ** attempt)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async def fetch_with_retry(session, url, attempts=3):\n    for i in range(attempts):\n        try:\n            return await session.get(url)\n        except ClientError:\n            if i == attempts - 1:\n                raise\n            await asyncio.sleep(2 ** i)","preventionTips":["Batch report downloads with small delays to avoid server connection drops.","Verify egress/firewall access to apps.fas.usda.gov from your runtime.","Use exponential backoff on ClientError, never immediate tight retries."],"tags":["network","psd","retry","usda"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}