{"record":{"id":"b0e7e96cc75e56be","repo":"influxdata/influxdb","slug":"body-content-is-not-valid-utf8-0","errorCode":null,"errorMessage":"body content is not valid utf8: {0}","messagePattern":"body content is not valid utf8: (.+?)","errorType":"http","errorClass":"Error::NonUtf8Body","httpStatus":null,"severity":"error","filePath":"influxdb3_server/src/http.rs","lineNumber":200,"sourceCode":"    fn from(e: AuthenticationError) -> Self {\n        Self::Authentication(e)\n    }\n}\n\nimpl From<ResourceAuthorizationError> for RoutingError {\n    fn from(e: ResourceAuthorizationError) -> Self {\n        Self::Authorization(e)\n    }\n}\n\n#[derive(Debug, Error)]\npub enum Error {\n    /// The requested path has no registered handler.\n    #[error(\"not found\")]\n    NoHandler,\n\n    /// The request body content is not valid utf8.\n    #[error(\"body content is not valid utf8: {0}\")]\n    NonUtf8Body(Utf8Error),\n\n    /// The `Content-Encoding` header is invalid and cannot be read.\n    #[error(\"invalid content-encoding header: {0}\")]\n    NonUtf8ContentEncodingHeader(hyper::header::ToStrError),\n\n    /// The `Content-Type` header is invalid and cannot be read.\n    #[error(\"invalid content-type header: {0}\")]\n    NonUtf8ContentTypeHeader(hyper::header::ToStrError),\n\n    /// The specified `Content-Encoding` is not acceptable.\n    #[error(\"unacceptable content-encoding: {0}\")]\n    InvalidContentEncoding(String),\n\n    /// The specified `Content-Type` is not acceptable.\n    #[error(\"unacceptable content-type, expected: {expected}\")]\n    InvalidContentType { expected: mime::Mime },\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_server/src/http.rs#L182-L218","documentation":"`Error::NonUtf8Body` is returned when the request body cannot be decoded as UTF-8. The server reads the body as a Rust String before handling the request, and this error wraps the underlying `Utf8Error` (shown as `{0}`).","triggerScenarios":"POSTing a write_lp/query payload that contains bytes outside valid UTF-8 — e.g. a binary-compressed body sent without Content-Encoding, Latin-1/Windows-1252 encoded files, or corrupted upload data.","commonSituations":"Scripts that read a line-protocol file with the wrong encoding, sending gzip or other binary data without declaring and applying encoding, copy-pasting characters that got mangled, or clients that prepend BOM/legacy encodings.","solutions":["Ensure the request body is valid UTF-8 before sending; re-encode the file or data (iconv -t utf-8, or set the correct source encoding)","If the payload is compressed, set the Content-Encoding header (e.g. gzip) so the server decodes it rather than parsing it as text","Log/print the raw body bytes around the failing offset to identify the offending characters","Escape or strip non-UTF-8 bytes in the producer before the HTTP call"],"exampleFix":"// before (Node)\nfetch(url, { method: 'POST', body: fs.readFileSync('lp.bin') });\n// after\nfetch(url, { method: 'POST', body: fs.readFileSync('lp.bin', 'utf8') });","handlingStrategy":"validation","validationCode":"function isUtf8(buf) { try { new TextDecoder('utf-8', { fatal: true }).decode(buf); return true; } catch { return false; } }","typeGuard":"function isUtf8Buffer(b) { return b instanceof Uint8Array && isUtf8(b); }","tryCatchPattern":"try { await send(body); } catch (e) { if (String(e).includes('not valid utf8')) { console.error('re-encode body as UTF-8'); } else throw e; }","preventionTips":["Always read/write payloads with explicit UTF-8 encoding","Declare Content-Encoding when sending binary/compressed data","Lint data pipelines for legacy encodings (Latin-1, Windows-1252)","Test payloads with a strict UTF-8 decoder before shipping"],"tags":["http","encoding","utf8"],"backgroundTag":"invalid-argument-format","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}