{"record":{"id":"58a392c680d35210","repo":"OpenBB-finance/OpenBB","slug":"server-error-fetching-report-report-id-csv-t","errorCode":null,"errorMessage":"Server error fetching report {report_id} -> {csv_text}","messagePattern":"Server 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":141,"sourceCode":"    # 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:\n        resp = make_request(\n            f\"https://apps.fas.usda.gov/PSDOnlineApi/api/query/GetMultiCommodityAttributes?commodityCodes={commodity_code},\"\n        )\n        if resp.status_code == 200:\n            data = resp.json()\n            id_to_key = {v: k for k, v in ATTRIBUTES.items()}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L123-L159","documentation":"After a successful fetch of the report CSV, the code checks whether the literal substring 'error' appears anywhere in the lowercased body. USDA's handler returns an HTML/CSV error page instead of data when the report handler fails (bad template combo, server fault), and this check converts that into an explicit OpenBBError including the server text.","triggerScenarios":"Requesting a report whose templateId/format combination is broken server-side; USDA server errors; requesting a report during a data refresh window.","commonSituations":"Report ids valid in metadata but removed on the live handler; transient USDA outages. Note the check is coarse: any CSV cell containing the word 'error' (e.g. a footnote) would also trip it.","solutions":["Retry later if the USDA service is having issues.","Confirm the report id and format are genuinely supported via list_reports().","If you hit a false positive (legitimate data containing 'error'), report it upstream as an over-broad check."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    parsed = await get_psd_report_data(report_id)\nexcept OpenBBError as e:\n    if \"Server error fetching report\" in str(e):\n        await asyncio.sleep(60)  # USDA handler hiccup; retry later\n        parsed = await get_psd_report_data(report_id)\n    else:\n        raise","preventionTips":["Treat server-error pages as transient; retry after a delay.","Confirm the report id/format combination in list_reports() before fetching.","Log the response body excerpt when this fires to distinguish real outages from false positives."],"tags":["upstream","psd","server-error","fragile-check"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}