OpenBB-finance/OpenBB · error · OpenBBError
Error with the request: {r.status_code}
Error message
Error with the request: {r.status_code} What it means
Raised by GovernmentUSTreasuryPricesFetchQueryParams.fetch_data when the POST to the US Treasury prices endpoint returns any HTTP status other than 200. The provider builds a form-encoded payload (priceDateDay/Month/Year, fileType=csv) and treats any non-200 as a hard failure, surfacing the raw status code in the message. This is a transport/upstream error, not a data-shape error.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py:89
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://treasurydirect.gov/",
"Content-Type": "application/x-www-form-urlencoded",
"Origin": "https://treasurydirect.gov",
"User-Agent": get_random_agent(),
}
payload = (
f"priceDateDay={query.date.day}" # type: ignore
f"&priceDateMonth={query.date.month}" # type: ignore
f"&priceDateYear={query.date.year}" # type: ignore
"&fileType=csv"
"&csv=CSV+FORMAT"
)
r = make_request(url=url, method="POST", headers=HEADERS, data=payload)
if r.status_code != 200:
raise OpenBBError("Error with the request: " + str(r.status_code))
if r.encoding != "ISO-8859-1":
raise OpenBBError(f"Expected ISO-8859-1 encoding but got: {r.encoding}")
return r.content.decode("utf-8")
@staticmethod
def transform_data(
query: GovernmentUSTreasuryPricesQueryParams,
data: str,
**kwargs: Any,
) -> list[GovernmentUSTreasuryPricesData]:
"""Transform the data."""
# pylint: disable=import-outside-toplevel
from math import isnan # noqa
from io import StringIO
from pandas import Index, read_csv, to_datetime
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Retry with a known trading/business date (e.g. a weekday that is not a federal holiday).
- If the status is 429 or 5xx, wait and retry; the upstream service is transiently unavailable.
- Check network/proxy configuration if the status is 403/407 or the request never reaches the Treasury host.
- If a valid business date consistently fails with 404, the upstream endpoint may have changed; check for an openbb-platform update or open an issue with the status code.
Example fix
// before obb.equity.gov.treasury_prices(date="2024-01-06").to_df() # Saturday // after obb.equity.gov.treasury_prices(date="2024-01-05").to_df() # Friday, a business day
Defensive patterns
Strategy: retry
Validate before calling
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
bdays = CustomBusinessDay(calendar=USFederalHolidayCalendar())
dates = pd.date_range("2024-01-01", "2024-03-31", freq=bdays) # only Treasury business days Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
res = obb.equity.gov.treasury_prices(date=d)
except OpenBBError as e:
code = str(e).rsplit(":", 1)[-1].strip()
if code in ("429", "503"):
time.sleep(30)
res = obb.equity.gov.treasury_prices(date=d)
else:
raise Prevention
- Pre-filter requested dates to US business days excluding federal holidays.
- Add exponential backoff around 429/5xx responses in batch jobs.
- Log the status code so failures are distinguishable (no-data vs outage).
When it happens
Trigger: Calling government_us.treasury_prices with a date the endpoint cannot serve (weekend, federal holiday, future date -> often 404), Treasury site maintenance or rate limiting (429/5xx), or an outbound network/proxy failure producing a non-200 response.
Common situations: Backfill scripts iterating over calendar dates that include Saturdays/Sundays; corporate proxies or VPNs intercepting the request; upstream Treasury endpoint changes after a site redesign.
Related errors
- Method must be GET or POST
- There was an error with the HTTP request
- Expected ISO-8859-1 encoding but got: {r.encoding}
- Failed to download document from {url}. Status code: {respon
- An error occurred while fetching constraints {dataflow_id}:
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/0eae4a737820c988.
Report an issue: GitHub.