
If your Python client raises json.decoder.JSONDecodeError: Extra data while reading a successful Ollama response, check whether you are parsing a stream as one JSON document.
Kingy test scope: On September 6, 2026, we reproduced this Python client error against a synthetic local HTTP server and verified two fixes. Python 3.14.0 on macOS. No Ollama daemon or model was installed or tested. The server fixtures follow the documented response shapes; they do not establish that a particular Ollama release is affected.
Identify this case
Inspect the response content type and a small, non-sensitive sample of the body. Several JSON objects separated by newlines indicate a different format from one JSON object containing the whole answer. Ollama documents default streaming for endpoints including /api/generate; the format is newline-delimited JSON. Official streaming documentation
Our fixture returned three lines: two content fragments and a completion marker. Passing that whole body to json.load(response) raised Extra data.
Fix A: request one response
For a native generate request, include the actual JSON boolean false:
{"model":"YOUR_INSTALLED_MODEL","prompt":"Say hello","stream":false}
Then parse the single response object. In our loopback test, json.load(response)["response"] returned A complete answer.. Sending "false" as a string is not the same JSON value.
Fix B: keep streaming and parse complete lines
Use the tested read_native_generate function in the downloadable lab. It decodes each complete line, collects the response fields, rejects error events, and requires done: true before returning success.
from ollama_client_lab import read_native_generate
# response is the opened native /api/generate HTTP response.
answer = read_native_generate(response)
The supplied fixture suite starts and stops its own loopback server. Run it without a model, account, or third-party package:
python3 ollama_client_lab.py
Expect extra-data to report pass: true. The script also checks incomplete streams and endpoint mismatches. Recorded results
When this does not fix it
This parser handles native generate NDJSON. It is not an OpenAI-compatible SSE reader, and native chat uses a different content field. Do not reuse it unchanged for those formats. If the body is an HTML proxy error, repair the request path or proxy; JSON parsing cannot fix that response. Extra data can also arise from unrelated concatenated JSON files.
Next: Match the API route and response shape, then catch errors after HTTP 200.
For hardware planning, Kingy Local Lab estimates memory fit. It does not diagnose this parser error or measure model quality.
Keep the test in context
These are client-protocol examples. For hardware fit estimates, use Local Lab; for the related setup walkthrough, read Kingy’s OpenClaw and UGREEN guide.