OpenBB-finance/OpenBB · error · OpenBBError

Failed to retrieve data. Unexpected response from the server

Error message

Failed to retrieve data. Unexpected response from the server. Status code: {response.status_code} -> Response content: {response_content}

What it means

Error "Failed to retrieve data. Unexpected response from the server. Status code: {response.status_code} -> Response content: {response_content}" thrown in OpenBB-finance/OpenBB.

Source

Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_report.py:163

        api_commodity = COMMODITIES.get(query.commodity.lower(), query.commodity)
        month = f"{query.month:02d}"
        url = f"https://apps.fas.usda.gov/PSDOnline/CircularDownloader.ashx?year={query.year}&month={month}&commodity={api_commodity}"
        output = b""

        try:
            response = make_request(url)

            if response.status_code == 404 or not response.content:
                raise OpenBBError(
                    ValueError(
                        "No data found for the given parameters. Please check the commodity, year, and month."
                    )
                )

            if response.status_code == 200 and response.content[:4] == b"%PDF":
                output = response.content
            else:
                raise OpenBBError(
                    ValueError(
                        "Failed to retrieve data. Unexpected response from the server."
                        + f" Status code: {response.status_code} -> "
                        + f"Response content: {response.content.decode('utf-8', errors='ignore')}"
                    )
                )
        except Exception as e:
            raise OpenBBError(e) from e

        return {"content": output}

    @staticmethod
    def transform_data(
        query: GovernmentUsCommodityPsdReportQueryParams,
        data: dict,
        **kwargs: Any,
    ) -> GovernmentUsCommodityPsdReportData:
        """Transform data into the encoded format."""

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Retry the request; the server returned an unexpected response.
  2. Check the status code and response content in the message for details.
  3. Try again later if the USDA server is having issues.

When it happens

Trigger: Thrown at openbb_platform/providers/government_us/openbb_government_us/models/commodity_psd_report.py:163 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/e4294f51534281db. Report an issue: GitHub.