OpenBB-finance/OpenBB · error · OpenBBError

Error fetching report {report_id} -> {e}

Error message

Error fetching report {report_id} -> {e}

What it means

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.

Source

Thrown at openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py:135

            template_id = group_data["reports"][report_id]["templateId"]
            break

    if template_id is None:
        raise OpenBBError(f"Invalid report ID -> {report_id} was not found.")

    # 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:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Retry with backoff; ClientError causes are frequently transient.
  2. Add delay/batching between report fetches to avoid the server closing connections.
  3. Verify egress to https://apps.fas.usda.gov (curl) from your environment.

Example fix

# before
html_resp = await session.get(html_url)

# after (bounded retry)
for attempt in range(3):
    try:
        html_resp = await session.get(html_url)
        break
    except ClientError:
        await asyncio.sleep(2 ** attempt)
Defensive patterns

Strategy: retry

Try / catch

async def fetch_with_retry(session, url, attempts=3):
    for i in range(attempts):
        try:
            return await session.get(url)
        except ClientError:
            if i == attempts - 1:
                raise
            await asyncio.sleep(2 ** i)

Prevention

When it happens

Trigger: 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.

Common situations: Bulk-download loops over many report ids that trip server-side connection limits; restricted egress environments (containers, CI) without access to usda.gov.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/bfc6661461798345. Report an issue: GitHub.