OtterMind/Chat2DB · error · RequestError

request body is too large

Error message

request body is too large

What it means

Raised by RelayHandler._read_payload (relay_server.py:208) as a RequestError(HTTP 413) when Content-Length is less than 1 or greater than MAX_REQUEST_BYTES (4096). The relay caps request size to protect memory; the bundled notifier's payload is well under this limit.

Source

Thrown at script/github/qq_relay/relay_server.py:208

        self.end_headers()
        self.wfile.write(body)

    def _authorize(self) -> None:
        expected = f"Bearer {self.relay_state.config.relay_token}"
        supplied = self.headers.get("Authorization", "")
        if not hmac.compare_digest(supplied, expected):
            raise RequestError(HTTPStatus.UNAUTHORIZED, "unauthorized")

    def _read_payload(self) -> Mapping[str, Any]:
        content_type = self.headers.get("Content-Type", "")
        if not content_type.lower().startswith("application/json"):
            raise RequestError(HTTPStatus.UNSUPPORTED_MEDIA_TYPE, "Content-Type must be JSON")
        try:
            content_length = int(self.headers.get("Content-Length", ""))
        except ValueError as error:
            raise RequestError(HTTPStatus.LENGTH_REQUIRED, "Content-Length is required") from error
        if content_length < 1 or content_length > MAX_REQUEST_BYTES:
            raise RequestError(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, "request body is too large")
        try:
            payload = json.loads(self.rfile.read(content_length).decode("utf-8"))
        except (UnicodeDecodeError, json.JSONDecodeError) as error:
            raise RequestError(HTTPStatus.BAD_REQUEST, "request body is not valid JSON") from error
        if not isinstance(payload, Mapping):
            raise RequestError(HTTPStatus.BAD_REQUEST, "request body must be a JSON object")
        return payload

    def _validate_payload(self, payload: Mapping[str, Any]) -> tuple[str, str]:
        config = self.relay_state.config
        if payload.get("repository") != config.repository:
            raise RequestError(HTTPStatus.FORBIDDEN, "repository is not allowed")
        delivery_id = payload.get("delivery_id")
        if not isinstance(delivery_id, str) or not DELIVERY_ID_PATTERN.fullmatch(delivery_id):
            raise RequestError(HTTPStatus.BAD_REQUEST, "delivery_id is invalid")
        message = payload.get("message")
        if not isinstance(message, str) or not message.strip():
            raise RequestError(HTTPStatus.BAD_REQUEST, "message must be non-empty text")

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Keep the total JSON request body under 4096 bytes.
  2. Ensure the message field is within the 900-character cap and remove unneeded fields.
  3. Verify Content-Length equals the actual body size.
Defensive patterns

Strategy: validation

Validate before calling

MAX_REQUEST_BYTES = 4096
body_len = len(body)
if body_len > MAX_REQUEST_BYTES:
    raise SystemExit(f"payload {body_len} bytes exceeds relay limit {MAX_REQUEST_BYTES}")

Prevention

When it happens

Trigger: A POST whose declared Content-Length is 0, negative, or exceeds 4096 bytes. An oversized message or an attempt to upload a large body triggers it.

Common situations: Sending a message longer than the limit; a client that adds large extra fields to the payload; a buggy client sending Content-Length far larger than the body; the notifier's message plus envelope approaching 4KB (the message itself is capped at 900 chars, so normally impossible from the notifier).

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/1b22160047977ec0. Report an issue: GitHub.