OpenBB-finance/OpenBB · error · OpenBBError
Expected ISO-8859-1 encoding but got: {r.encoding}
Error message
Expected ISO-8859-1 encoding but got: {r.encoding} What it means
Raised after a successful 200 response when the response object's detected encoding is not exactly 'ISO-8859-1'. The provider hard-codes this expectation because the Treasury CSV endpoint historically returned that charset; if the server stops advertising it (or an intermediary rewrites the Content-Type header), the strict equality check fails even though the payload may be fine. Note the code then decodes with utf-8 regardless, so the check is about the header, not the bytes.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py:92
"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
try:
if not data:
raise EmptyDataError("Data not found")View on GitHub (pinned to 3e071fcc2c)
Solutions
- Confirm with curl -I that the endpoint's Content-Type header still declares charset=ISO-8859-1.
- If upstream changed the charset permanently, update to a newer openbb-platform release where the check was adjusted, or patch the check locally to accept the new encoding.
- Remove any intermediary (proxy/cache) that rewrites response headers and retest.
- If you control a fork, decode based on r.content directly instead of gating on r.encoding.
Example fix
# before (strict header equality)
if r.encoding != "ISO-8859-1":
raise OpenBBError(f"Expected ISO-8859-1 encoding but got: {r.encoding}")
# after (tolerate header drift, decode bytes directly)
return r.content.decode("utf-8", errors="replace") Defensive patterns
Strategy: try-catch
Try / catch
try:
res = obb.equity.gov.treasury_prices(date=d)
except OpenBBError as e:
if "Expected ISO-8859-1" in str(e):
# header drift from upstream/proxy; verify with curl -I and file an upstream issue
log.warning("encoding gate hit for %s", d)
else:
raise Prevention
- Monitor the endpoint's Content-Type with a health check if you rely on this feed in production.
- Avoid proxies that rewrite response headers for us treasury endpoints.
- Pin a known-good openbb-platform version and test before upgrading.
When it happens
Trigger: The Treasury endpoint changes its Content-Type charset (e.g. to utf-8 or omits charset so the HTTP library guesses differently); a corporate proxy or cache rewrites response headers; using a different HTTP backend whose encoding detection differs.
Common situations: Upstream server configuration changes after Treasury site updates; environments with MITM proxies (Zscaler, corporate squid) that normalize headers; library upgrades that change default charset sniffing.
Related errors
- Error with the request: {r.status_code}
- Server error fetching report {report_id} -> {csv_text}
- Method must be GET or POST
- Invalid base64-encoded token.
- methods must be a list of strings
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/a63ad48d120bddc1.
Report an issue: GitHub.