aio-libs/aiohttp · error · LineTooLong
Got more than {limit} bytes when reading: {line!r}.
Error message
Got more than {limit} bytes when reading: {line!r}. What it means
Raised as LineTooLong (a BadHttpMessage subclass) by StreamReader.readuntil when the accumulated chunk exceeds max_size before a separator is found. The message is 'Got more than {limit} bytes when reading: {line!r}.' with line truncated to 100 bytes. max_size defaults to the stream's _high_water mark but can be overridden via the max_size/max_line_length kwargs of readuntil/readline. This protects servers from unbounded single-line bodies (think a 10GB header-less payload).
Source
Thrown at aiohttp/streams.py:410
chunk_size = 0
not_enough = True
max_size = max_size or self._high_water
while not_enough:
while self._buffer and not_enough:
offset = self._buffer_offset
ichar = self._buffer[0].find(separator, offset) + 1
# Read from current offset to found separator or to the end.
data = self._read_nowait_chunk(
ichar - offset + seplen - 1 if ichar else -1
)
chunk += data
chunk_size += len(data)
if ichar:
not_enough = False
if chunk_size > max_size:
raise LineTooLong(chunk[:100] + b"...", max_size)
if self._eof:
break
if not_enough:
await self._wait("readuntil")
if chunk and self._on_chunk_received is not None:
await self._fire_chunk_received(chunk)
return chunk
async def read(self, n: int = -1) -> bytes:
if self._exception is not None:
raise self._exception
if not n:
return b""
View on GitHub (pinned to c0ef574e29)
Solutions
- Raise the limit explicitly: `await request.content.readline(max_line_length=16 * 1024 * 1024)`.
- Switch from line-oriented to chunk-oriented reads: `await request.content.readany()` to drain in blocks.
- Re-check the upstream — a missing newline often signals a malformed protocol or wrong content-type.
- Increase reader's high water via StreamReader(... read_buf_size=...) if appropriate.
Example fix
// before line = await request.content.readline() # default ~64KiB limit // after line = await request.content.readline(max_line_length=8 * 1024 * 1024)
Defensive patterns
Strategy: try-catch
Try / catch
from aiohttp.http_exceptions import LineTooLong
try:
line = await stream.readline()
except LineTooLong as e:
# either raise the limit or switch to block reads
line = await stream.readany() Prevention
- Pass max_line_length explicitly when you expect large lines.
- Prefer readany() for unbounded streaming bodies.
- Validate Content-Type and framing when lines blow the limit unexpectedly.
When it happens
Trigger: await request.content.readline() against a body with no newline within the limit; await request.content.readuntil(b'\r\n') on a streaming JSON-or-CSV line larger than max_size; client reading a server response whose status line / headers exceed the limit (http parser also uses this path).
Common situations: Uploading large base64 blobs without line breaks; servers streaming JSON-lines where one record is enormous; default _high_water too low for legitimate payloads; misconfigured client_max_size interaction.
Related errors
- Method cannot contain non-token characters {method!r} (found
- Got more than {limit} bytes when reading: {line!r}.
- Duplicate '{name}' header found.
- Too many headers received
- Transfer-Encoding can't be present with Content-Length
AI-assisted analysis of aio-libs/aiohttp@c0ef574e29 (2026-08-04).
Data as JSON: /data/errors/192ec574d4043d83.json.
Report an issue: GitHub.