influxdata/influxdb · error · Error::InvalidContentType
unacceptable content-type, expected
Error message
unacceptable content-type, expected: {expected} What it means
`Error::InvalidContentType` is returned when the request's `Content-Type` is not acceptable for the endpoint; the error message includes the `expected` MIME type parsed into `mime::Mime`. Handlers require a specific media type (e.g. text/plain for line protocol) to parse the body correctly.
Solutions
- Set the Content-Type header to the expected value shown in the error message (e.g. text/plain for line protocol)
- Match the endpoint to your payload format: JSON endpoints expect application/json, line protocol expects text/plain
- Remove extra parameters from the Content-Type if they cause the mime parse/accept check to fail
- Consult the endpoint docs in influxdb3_server for the accepted media types
Example fix
// before curl -X POST http://localhost:8181/api/v3/write_lp?db=mydb -H 'Content-Type: application/json' --data-binary @metrics.lp // after curl -X POST http://localhost:8181/api/v3/write_lp?db=mydb -H 'Content-Type: text/plain' --data-binary @metrics.lp
Defensive patterns
Strategy: validation
Validate before calling
function matchesExpected(ct, expectedPrefix) { return typeof ct === 'string' && ct.startsWith(expectedPrefix); }
// e.g. matchesExpected(headers['content-type'], 'text/plain') before calling write_lp Try / catch
try { await writeLP(lines); } catch (e) { if (String(e).includes('unacceptable content-type')) { headers.set('Content-Type','text/plain'); retry(); } else throw e; } Prevention
- Set Content-Type explicitly per endpoint (text/plain for line protocol, application/json for JSON APIs)
- Read the expected type from the error message and align your header
- Don't reuse one generic client config across JSON and line-protocol endpoints
- Add integration tests asserting request headers
When it happens
Trigger: POSTing line protocol without `Content-Type: text/plain` or application/xml variants the handler expects; sending JSON to a line-protocol endpoint or vice versa; missing Content-Type header entirely on strict handlers.
Common situations: Using the wrong endpoint for the payload format (v3 write_lp vs query JSON APIs), clients defaulting to application/x-www-form-urlencoded, or copying a curl example with an incorrect header.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- invalid mime type ( )
- invalid content-type header
- invalid mime type ( )
- invalid mime type ( )
- the mime type specified was not valid UTF8
AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19).
Data as JSON: /api/errors/23397b59f8546d8e.
Report an issue: GitHub.
Appendix: source
Thrown at influxdb3_server/src/http.rs:216
/// The request body content is not valid utf8.
#[error("body content is not valid utf8: {0}")]
NonUtf8Body(Utf8Error),
/// The `Content-Encoding` header is invalid and cannot be read.
#[error("invalid content-encoding header: {0}")]
NonUtf8ContentEncodingHeader(hyper::header::ToStrError),
/// The `Content-Type` header is invalid and cannot be read.
#[error("invalid content-type header: {0}")]
NonUtf8ContentTypeHeader(hyper::header::ToStrError),
/// The specified `Content-Encoding` is not acceptable.
#[error("unacceptable content-encoding: {0}")]
InvalidContentEncoding(String),
/// The specified `Content-Type` is not acceptable.
#[error("unacceptable content-type, expected: {expected}")]
InvalidContentType { expected: mime::Mime },
/// The client disconnected.
#[error("client disconnected")]
ClientHangup(Box<dyn std::error::Error + Send + Sync>),
/// The client sent a request body that exceeds the configured maximum.
#[error("max request size ({0} bytes) exceeded")]
RequestSizeExceeded(usize),
/// Decoding a gzip-compressed stream of data failed.
#[error("error decoding gzip stream: {0}")]
InvalidGzip(std::io::Error),
#[error("invalid mime type ({0})")]
InvalidMimeType(String),
/// DatabaseName validation error.View on GitHub (pinned to 06200ef96b)