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
- 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.
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
- 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.
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
- Congress.gov API rate limit exceeded. Please wait a moment a
- Failed to get futures curve -> {e.__class__.__name__ if hasa
- Report ID {report_id} not found. Use list_reports() to see a
- Failed to fetch data for port {port_code}: {e} -> {e.args}
- Error fetching port data: {result} -> {result.args[0]}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/bfc6661461798345.
Report an issue: GitHub.