OpenBMB/ChatDev · error · ConfigError

encoding cannot be empty

Error message

encoding cannot be empty

What it means

PythonRunnerConfig.from_dict defaults encoding to 'utf-8'; if an explicit 'encoding' value normalizes to an empty string (e.g. encoding: '' or whitespace-only), this ConfigError is raised at '<path>.encoding'.

Source

Thrown at entity/configs/node/python_runner.py:42

    interpreter: str = field(default_factory=_default_interpreter)
    args: List[str] = field(default_factory=list)
    env: Dict[str, str] = field(default_factory=dict)
    timeout_seconds: int = 60
    encoding: str = "utf-8"

    @classmethod
    def from_dict(cls, data: Mapping[str, Any], *, path: str) -> "PythonRunnerConfig":
        mapping = require_mapping(data, path)
        interpreter = optional_str(mapping, "interpreter", path) or _default_interpreter()
        args_raw = mapping.get("args")
        args = [str(item) for item in ensure_list(args_raw)] if args_raw is not None else []
        env = optional_dict(mapping, "env", path) or {}
        timeout_value = mapping.get("timeout_seconds", 60)
        if not isinstance(timeout_value, int) or timeout_value <= 0:
            raise ConfigError("timeout_seconds must be a positive integer", f"{path}.timeout_seconds")
        encoding = optional_str(mapping, "encoding", path) or "utf-8"
        if not encoding:
            raise ConfigError("encoding cannot be empty", f"{path}.encoding")
        return cls(
            interpreter=interpreter,
            args=args,
            env={str(key): str(value) for key, value in env.items()},
            timeout_seconds=timeout_value,
            encoding=encoding,
            path=path,
        )

    FIELD_SPECS = {
        "interpreter": ConfigFieldSpec(
            name="interpreter",
            display_name="Python Path",
            type_hint="str",
            required=False,
            default=_default_interpreter(),
            description="Python executable file path, defaults to current process interpreter",
            advance=True,

View on GitHub (pinned to 4fb2db0ea9)

Solutions

  1. Remove the empty encoding key to use the utf-8 default
  2. Set a valid codec name such as utf-8 or gbk
  3. Strip/skip empty env-derived values before building config

Example fix

# before
encoding: ''
# after
encoding: utf-8
Defensive patterns

Strategy: validation

Validate before calling

enc = cfg.get('encoding') or 'utf-8'
assert enc.strip(), 'encoding must be non-empty'

Try / catch

try:
    PythonRunnerConfig.from_dict(d, path='config')
except ConfigError as e:
    if 'encoding' in str(e):
        d.pop('encoding', None)  # fall back to utf-8 default
        PythonRunnerConfig.from_dict(d, path='config')

Prevention

When it happens

Trigger: Setting encoding: "" or a whitespace-only string in the python_runner config.

Common situations: Template-generated configs leaving encoding empty; env var interpolation producing an empty string; a linter stripping the value.

Related errors


AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27). Data as JSON: /api/errors/b8066c6342b20a47. Report an issue: GitHub.