{"record":{"id":"0eae4a737820c988","repo":"OpenBB-finance/OpenBB","slug":"error-with-the-request-r-status-code","errorCode":null,"errorMessage":"Error with the request: {r.status_code}","messagePattern":"Error with the request: (.+?)","errorType":"http","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py","lineNumber":89,"sourceCode":"            \"Accept-Encoding\": \"gzip, deflate, br\",\n            \"Referer\": \"https://treasurydirect.gov/\",\n            \"Content-Type\": \"application/x-www-form-urlencoded\",\n            \"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","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/models/treasury_prices.py#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nobb.equity.gov.treasury_prices(date=\"2024-01-06\").to_df()  # Saturday\n\n// after\nobb.equity.gov.treasury_prices(date=\"2024-01-05\").to_df()  # Friday, a business day","handlingStrategy":"retry","validationCode":"from pandas.tseries.holiday import USFederalHolidayCalendar\nfrom pandas.tseries.offsets import CustomBusinessDay\n\nbdays = CustomBusinessDay(calendar=USFederalHolidayCalendar())\ndates = pd.date_range(\"2024-01-01\", \"2024-03-31\", freq=bdays)  # only Treasury business days","typeGuard":null,"tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\n\ntry:\n    res = obb.equity.gov.treasury_prices(date=d)\nexcept OpenBBError as e:\n    code = str(e).rsplit(\":\", 1)[-1].strip()\n    if code in (\"429\", \"503\"):\n        time.sleep(30)\n        res = obb.equity.gov.treasury_prices(date=d)\n    else:\n        raise","preventionTips":["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)."],"tags":["network","http","treasury","upstream"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}