{"record":{"id":"a63ad48d120bddc1","repo":"OpenBB-finance/OpenBB","slug":"expected-iso-8859-1-encoding-but-got-r-encoding","errorCode":null,"errorMessage":"Expected ISO-8859-1 encoding but got: {r.encoding}","messagePattern":"Expected ISO-8859-1 encoding but got: (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py","lineNumber":92,"sourceCode":"            \"Origin\": \"https://treasurydirect.gov\",\n            \"User-Agent\": get_random_agent(),\n        }\n\n        payload = (\n            f\"priceDateDay={query.date.day}\"  # type: ignore\n            f\"&priceDateMonth={query.date.month}\"  # type: ignore\n            f\"&priceDateYear={query.date.year}\"  # type: ignore\n            \"&fileType=csv\"\n            \"&csv=CSV+FORMAT\"\n        )\n\n        r = make_request(url=url, method=\"POST\", headers=HEADERS, data=payload)\n\n        if r.status_code != 200:\n            raise OpenBBError(\"Error with the request: \" + str(r.status_code))\n\n        if r.encoding != \"ISO-8859-1\":\n            raise OpenBBError(f\"Expected ISO-8859-1 encoding but got: {r.encoding}\")\n\n        return r.content.decode(\"utf-8\")\n\n    @staticmethod\n    def transform_data(\n        query: GovernmentUSTreasuryPricesQueryParams,\n        data: str,\n        **kwargs: Any,\n    ) -> list[GovernmentUSTreasuryPricesData]:\n        \"\"\"Transform the data.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        from math import isnan  # noqa\n        from io import StringIO\n        from pandas import Index, read_csv, to_datetime\n\n        try:\n            if not data:\n                raise EmptyDataError(\"Data not found\")","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py#L74-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before (strict header equality)\nif r.encoding != \"ISO-8859-1\":\n    raise OpenBBError(f\"Expected ISO-8859-1 encoding but got: {r.encoding}\")\n\n# after (tolerate header drift, decode bytes directly)\nreturn r.content.decode(\"utf-8\", errors=\"replace\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    res = obb.equity.gov.treasury_prices(date=d)\nexcept OpenBBError as e:\n    if \"Expected ISO-8859-1\" in str(e):\n        # header drift from upstream/proxy; verify with curl -I and file an upstream issue\n        log.warning(\"encoding gate hit for %s\", d)\n    else:\n        raise","preventionTips":["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."],"tags":["http","encoding","upstream","fragile-check"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}