infiniflow/ragflow · error · ValueError
Invalid base64 encoding: {str(e)}
Error message
Invalid base64 encoding: {str(e)} What it means
Error "Invalid base64 encoding: {str(e)}" thrown in infiniflow/ragflow.
Source
Thrown at agent/tools/code_exec.py:222
class Language(StrEnum):
PYTHON = "python"
NODEJS = "nodejs"
class CodeExecutionRequest(BaseModel):
code_b64: str = Field(..., description="Base64 encoded code string")
language: str = Field(default=Language.PYTHON.value, description="Programming language")
arguments: Optional[dict] = Field(default={}, description="Arguments")
@field_validator("code_b64")
@classmethod
def validate_base64(cls, v: str) -> str:
try:
base64.b64decode(v, validate=True)
return v
except Exception as e:
raise ValueError(f"Invalid base64 encoding: {str(e)}")
@field_validator("language", mode="before")
@classmethod
def normalize_language(cls, v) -> str:
if isinstance(v, str):
low = v.lower()
if low in ("python", "python3"):
return "python"
elif low in ("javascript", "nodejs"):
return "nodejs"
raise ValueError(f"Unsupported language: {v}")
class CodeExecParam(ToolParamBase):
"""
Define the code sandbox component parameters.
"""
View on GitHub (pinned to 554fb1133a)
Solutions
- Ensure the attachment content is valid base64 before decoding.
- Strip whitespace and use base64.b64decode with validate=True to catch bad input early.
Example fix
import base64 data = base64.b64decode(payload, validate=True)
When it happens
Trigger: Thrown at agent/tools/code_exec.py:222 when the library encounters an invalid state.
Common situations: A base64 payload passed to CodeExec is truncated, URL-encoded, or contains invalid characters; validating the encoding before decode prevents this error.
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/c1354d43ae690387.
Report an issue: GitHub.