{"record":{"id":"1256ec54098c42ba","repo":"infiniflow/ragflow","slug":"invalid-base64-encoding-str-e","errorCode":null,"errorMessage":"Invalid base64 encoding: {str(e)}","messagePattern":"Invalid base64 encoding: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"agent/sandbox/executor_manager/models/schemas.py","lineNumber":72,"sourceCode":"    artifacts: list[ArtifactItem] = []\n\n    # Structured return value produced by main()\n    result: Optional[ExecutionStructuredResult] = None\n\n\nclass CodeExecutionRequest(BaseModel):\n    code_b64: str = Field(..., description=\"Base64 encoded code string\")\n    language: SupportLanguage = Field(default=SupportLanguage.PYTHON, description=\"Programming language\")\n    arguments: Optional[dict] = Field(default={}, description=\"Arguments\")\n\n    @field_validator(\"code_b64\")\n    @classmethod\n    def validate_base64(cls, v: str) -> str:\n        try:\n            base64.b64decode(v, validate=True)\n            return v\n        except Exception as e:\n            raise ValueError(f\"Invalid base64 encoding: {str(e)}\")\n","sourceCodeStart":54,"sourceCodeEnd":73,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/executor_manager/models/schemas.py#L54-L73","documentation":"ValueError raised by a Pydantic field_validator on CodeExecutionRequest.code_b64 in the sandbox executor's API models. The field must be valid base64; b64decode(v, validate=True) is run on input, and any exception (binascii.Error for bad characters/length, or non-str input) is converted into this message.","triggerScenarios":"POSTing to the sandbox executor API with code_b64 containing characters outside the base64 alphabet, wrong padding, or sending raw source code instead of base64-encoding it first. validate=True makes even stray whitespace/newlines fail.","commonSituations":"Client forgets base64.b64encode and posts plain code; URL-safe base64 (urlsafe_b64encode with -/_) sent where standard base64 is expected; padding stripped by a URL path segment; double-encoding mismatches between client and server versions.","solutions":["Encode the code before sending: base64.b64encode(code.encode('utf-8')).decode('ascii') and send the result as code_b64.","If you used urlsafe_b64encode, switch to standard b64encode (or translate -_ to +/ and re-pad).","Ensure padding ('=') is preserved and no newlines/whitespace are introduced in transit."],"exampleFix":"# before\nrequests.post(url, json={\"code_b64\": \"print('hi')\"})\n\n# after\nimport base64\nrequests.post(url, json={\"code_b64\": base64.b64encode(\"print('hi')\".encode()).decode()})","handlingStrategy":"validation","validationCode":"import base64, binascii\n\ndef is_valid_standard_b64(s: str) -> bool:\n    try:\n        base64.b64decode(s, validate=True)\n        return True\n    except (binascii.Error, ValueError):\n        return False\n\n# before POSTing:\nassert is_valid_standard_b64(payload['code_b64'])","typeGuard":"import base64, binascii\n\ndef is_standard_base64(s: str) -> bool:\n    try:\n        base64.b64decode(s, validate=True)\n        return True\n    except (binascii.Error, ValueError):\n        return False","tryCatchPattern":"try:\n    resp = requests.post(executor_url, json=payload)\n    resp.raise_for_status()\nexcept requests.HTTPError as e:\n    if 'Invalid base64 encoding' in e.response.text:\n        payload['code_b64'] = base64.b64encode(raw_code.encode()).decode()\n        resp = requests.post(executor_url, json=payload)","preventionTips":["Always base64.b64encode (standard alphabet) code on the client; never send raw source.","Preserve '=' padding and avoid URL-safe variants unless the server documents support.","Centralize encode/decode in one helper to prevent double-encoding drift."],"tags":["sandbox","base64","api-validation","pydantic"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}