infiniflow/ragflow · error · RuntimeError

invalid json response: {text[:200]}

Error message

invalid json response: {text[:200]}

What it means

Error "invalid json response: {text[:200]}" thrown in infiniflow/ragflow.

Source

Thrown at api/channels/whatsapp/channel.py:133

        url = self._gateway_url(path)
        async with session.request(
            method,
            url,
            json=payload,
            headers=self._gateway_headers(),
        ) as resp:
            text = await resp.text()
            if resp.status >= 400:
                raise RuntimeError(f"status: {resp.status}, response: {text}")
            if not text.strip():
                return {}
            content_type = resp.headers.get("content-type", "")
            if "application/json" not in content_type.lower():
                raise RuntimeError(f"unexpected response content-type: {content_type or 'unknown'}, response: {text[:200]}")
            try:
                return await resp.json()
            except Exception as ex:
                raise RuntimeError(f"invalid json response: {text[:200]}") from ex

    async def _request_json_with_retry(
        self,
        method: str,
        path: str,
        payload: dict[str, Any] | None = None,
    ) -> dict[str, Any]:
        deadline = time.time() + WHATSAPP_GATEWAY_START_RETRY_SECS
        last_error: Exception | None = None
        while time.time() < deadline and not self._stop_event.is_set():
            try:
                return await self._request_json(method, path, payload)
            except (aiohttp.ClientError, asyncio.TimeoutError, OSError) as ex:
                last_error = ex
                await asyncio.sleep(0.5)
        if last_error is not None:
            raise last_error
        return await self._request_json(method, path, payload)

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Check the raw gateway response body; it must be valid JSON.
  2. Confirm the gateway version matches the expected API contract.

Example fix

try:
    data = json.loads(text)
except json.JSONDecodeError:
    raise Exception(f'invalid json response: {text[:200]}')

When it happens

Trigger: Thrown at api/channels/whatsapp/channel.py:133 when the library encounters an invalid state.

Common situations: The WhatsApp gateway returns malformed or truncated JSON; logging the raw body and validating the gateway build prevents this error.

Understand the failure class


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/e8e8beb494f0d25d. Report an issue: GitHub.