OpenBB-finance/OpenBB · error · OpenBBError
Unexpected data format. Expected 'ratings' key, got: {list(d
Error message
Unexpected data format. Expected 'ratings' key, got: {list(data.keys())} What it means
BenzingaPriceTargetFetcher.a_fetch_data (price_target.py:297) validates the shape of Benzinga's /calendar/ratings payload: a dict that does not contain a 'ratings' key raises OpenBBError("Unexpected data format. Expected 'ratings' key, got: {list(data.keys())}"). The endpoint answered 200 with JSON, but the body is not the expected wrapper — typically an error/limit object or a schema revision.
Source
Thrown at openbb_platform/providers/benzinga/openbb_benzinga/models/price_target.py:297
query: BenzingaPriceTargetQueryParams,
credentials: dict[str, str] | None,
**kwargs: Any,
) -> list[dict]:
"""Return the raw data from the Benzinga endpoint."""
# pylint: disable=import-outside-toplevel
from openbb_benzinga.utils.helpers import response_callback
from openbb_core.provider.utils.helpers import amake_request, get_querystring
token = credentials.get("benzinga_api_key") if credentials else ""
base_url = "https://api.benzinga.com/api/v2.1/calendar/ratings"
query.limit = query.limit or 200
querystring = get_querystring(query.model_dump(by_alias=True), [])
url = f"{base_url}?{querystring}&token={token}"
data = await amake_request(url, response_callback=response_callback, **kwargs)
if isinstance(data, dict) and "ratings" not in data:
raise OpenBBError(
f"Unexpected data format. Expected 'ratings' key, got: {list(data.keys())}"
)
if not isinstance(data, dict):
raise OpenBBError(
f"Unexpected data format. Expected dict, got: {type(data)}"
)
if isinstance(data, dict) and not data.get("ratings"):
raise EmptyDataError("No ratings data returned.")
return data["ratings"]
@staticmethod
def transform_data(
query: BenzingaPriceTargetQueryParams,
data: list[dict],
**kwargs: Any,
) -> list[BenzingaPriceTargetData]:
"""Return the transformed data."""View on GitHub (pinned to 3e071fcc2c)
Solutions
- Read list(data.keys()) from the message to identify the actual body (look for 'error'/'message').
- Refresh the benzinga_api_key credential and confirm quota status in the Benzinga console.
- Upgrade openbb-benzinga to pick up current schema handling.
- Handle OpenBBError distinctly from EmptyDataError so auth/schema issues surface instead of masquerading as no-data.
Example fix
# before
data = await amake_request(url, response_callback=response_callback)
# OpenBBError: Unexpected data format. Expected 'ratings' key, got: ['message']
# after
if isinstance(data, dict) and "ratings" not in data:
msg = data.get("message") or data.get("error") or list(data.keys())
raise OpenBBError(f"Benzinga price-target endpoint replied: {msg}") Defensive patterns
Strategy: try-catch
Validate before calling
# Pre-flight: confirm key works and payload shape is current
probe = await amake_request(base_url + "?limit=1&token=" + token, response_callback=response_callback)
if not (isinstance(probe, dict) and "ratings" in probe):
raise RuntimeError(f"Benzinga contract changed or auth failed: {list(probe.keys()) if isinstance(probe, dict) else type(probe)}") Type guard
def is_ratings_payload(data) -> bool:
return isinstance(data, dict) and "ratings" in data Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
rows = await fetcher.a_fetch_data(query, credentials)
except OpenBBError as e:
if "Expected 'ratings' key" in str(e):
# inspect reported keys; typically auth/quota or schema revision
logger.error("Benzinga price-target payload unexpected: %s", e)
raise Prevention
- Monitor Benzinga quota and key expiry in dashboards.
- Pin openbb-benzinga to a release matched to the API, and upgrade deliberately.
- Don't conflate OpenBBError with EmptyDataError in handlers.
When it happens
Trigger: Benzinga returns {"error": ...}, an auth notice, or renames/adds wrapper keys, so 'ratings' is absent from an otherwise valid dict.
Common situations: Invalid/expired API key, monthly-call quota exceeded (AV-style message bodies), or an API version change after openbb-benzinga was pinned.
Related errors
- Unexpected data format. Expected 'analyst_ratings_analyst' k
- No ratings data returned.
- Unexpected data format. Expected dict, got: {type(data).__na
- The request was returned empty.
- Unexpected data format. Expected dict, got: {type(data)}
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/12a15e33603abc71.
Report an issue: GitHub.