OpenBB-finance/OpenBB · error · ValueError
Country value cannot be empty.
Error message
Country value cannot be empty.
What it means
Raised at the top of the country-resolution helper in dot_helpers.py when the incoming value is falsy (empty string, None after strip, empty list item). The function maps user-friendly country input to IMF SDMX area codes, and an empty input cannot map to anything, so it fails fast instead of sending an invalid query to the IMF API.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py:84
(e.g., 'united_states'). Returns the ISO code.
Parameters
----------
value : str
Country code or name to resolve.
Returns
-------
str
The resolved ISO country code.
Raises
------
ValueError
If the input cannot be resolved to a valid country code.
"""
if not value:
raise ValueError("Country value cannot be empty.")
# Handle wildcards
if value.lower() in ["all", "*"]:
return "*"
# Common aliases for frequently used regions
common_aliases = {
"world": "G001",
"euro_area": "G163",
"eurozone": "G163",
"eu": "G998",
"european_union": "G998",
"europe": "GX170",
}
v_lower = value.lower().replace(" ", "_")
# Check common aliases firstView on GitHub (pinned to 3e071fcc2c)
Solutions
- Supply a non-empty country: ISO3 code ('USA') or snake_case name ('united_states').
- Filter empty entries out of lists before calling: [c for c in countries if c and c.strip()].
- Use '*' or 'all' when the intent is 'every country' — the helper maps those to the wildcard.
Example fix
# before countries = ['USA', '', 'DEU'] res = imts_query(country=countries, counterpart='all', indicator='TXG_FOB_USD') # after countries = [c for c in ['USA', '', 'DEU'] if c] res = imts_query(country=countries, counterpart='all', indicator='TXG_FOB_USD')
Defensive patterns
Strategy: validation
Validate before calling
countries = [c.strip() for c in (countries or []) if c and c.strip()]
if not countries:
raise ValueError('At least one country is required.')
res = imts_query(country=countries, counterpart='*', indicator='TXG_FOB_USD') Type guard
def is_non_empty_country(value: str | list[str] | None) -> bool:
if value is None:
return False
items = [value] if isinstance(value, str) else value
return any(isinstance(i, str) and i.strip() for i in items) Try / catch
try:
code = transform_country(raw)
except ValueError as e:
if 'cannot be empty' in str(e):
raise ValueError(f'Country field is required, got: {raw!r}') from e
raise Prevention
- Filter blank strings out of country lists before calling.
- Make country fields required in your forms/schemas.
- Use '*'/'all' for wildcard intent instead of empty values.
When it happens
Trigger: Calling a DOT/IMTS helper with country='' or None; a list of countries containing an empty entry (['USA', '']); stripping user input to '' before passing it in.
Common situations: Form fields left blank; CSV/config rows with missing country columns; loops that pass variables which are conditionally set and sometimes remain None.
Related errors
- Country '{value}' is not a valid IMF country code or country
- Country and counterpart parameters cannot be empty.
- Frequency must be one of 'A', 'Q', or 'M'.
- Invalid {name}(s): {', '.join(invalid)}
- No valid port_code provided.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/114166419ff2056d.
Report an issue: GitHub.