OpenBB-finance/OpenBB · error · OpenBBError
Server error fetching report
Error message
Server error fetching report {report_id} -> {csv_text} What it means
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.
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.
Defensive patterns
Strategy: retry
Try / catch
try:
parsed = await get_psd_report_data(report_id)
except OpenBBError as e:
if "Server error fetching report" in str(e):
await asyncio.sleep(60) # USDA handler hiccup; retry later
parsed = await get_psd_report_data(report_id)
else:
raise Prevention
- 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.
When it happens
Trigger: Requesting a report whose templateId/format combination is broken server-side; USDA server errors; requesting a report during a data refresh window.
Common situations: 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.
Related errors
- Expected ISO-8859-1 encoding but got
- Agency ID not found for dataflow
- Attribute ' ' is not available for . Valid attributes
- Country ' ' is not available for . Valid countries
- Error fetching report
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/58a392c680d35210.
Report an issue: GitHub.
Appendix: source
Thrown at openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py:141
# Build URLs for both formats
html_url = get_report_url(report_id, "html")
csv_url = get_report_url(report_id, "csv")
session = await get_async_requests_session()
try:
# Fetch both HTML (for units) and CSV (for data)
html_resp = await session.get(html_url)
html = await html_resp.text()
csv_resp = await session.get(csv_url)
csv_text = await csv_resp.text()
except ClientError as e:
raise OpenBBError(f"Error fetching report {report_id} -> {e}") from e
finally:
await session.close()
# Check for server error
if "error" in csv_text.lower():
raise OpenBBError(f"Server error fetching report {report_id} -> {csv_text}")
lines = csv_text.replace("\r", "").strip().split("\n")
return parse_report(template_id, lines, html)
def _get_commodity_attributes(commodity_code: str) -> list[str]:
"""Fetch valid attribute names for a commodity using the metadata API."""
# pylint: disable=import-outside-toplevel
from openbb_core.provider.utils.helpers import make_request
try:
resp = make_request(
f"https://apps.fas.usda.gov/PSDOnlineApi/api/query/GetMultiCommodityAttributes?commodityCodes={commodity_code},"
)
if resp.status_code == 200:
data = resp.json()
id_to_key = {v: k for k, v in ATTRIBUTES.items()}View on GitHub (pinned to 3e071fcc2c)