{"id":"192ec574d4043d83","repo":"aio-libs/aiohttp","slug":"got-more-than-limit-bytes-when-reading-line-r-192ec5","errorCode":null,"errorMessage":"Got more than {limit} bytes when reading: {line!r}.","messagePattern":"Got more than (.+?) bytes when reading: (.+?)\\.","errorType":"exception","errorClass":"LineTooLong","httpStatus":400,"severity":"error","filePath":"aiohttp/streams.py","lineNumber":410,"sourceCode":"        chunk_size = 0\n        not_enough = True\n        max_size = max_size or self._high_water\n\n        while not_enough:\n            while self._buffer and not_enough:\n                offset = self._buffer_offset\n                ichar = self._buffer[0].find(separator, offset) + 1\n                # Read from current offset to found separator or to the end.\n                data = self._read_nowait_chunk(\n                    ichar - offset + seplen - 1 if ichar else -1\n                )\n                chunk += data\n                chunk_size += len(data)\n                if ichar:\n                    not_enough = False\n\n                if chunk_size > max_size:\n                    raise LineTooLong(chunk[:100] + b\"...\", max_size)\n\n            if self._eof:\n                break\n\n            if not_enough:\n                await self._wait(\"readuntil\")\n\n        if chunk and self._on_chunk_received is not None:\n            await self._fire_chunk_received(chunk)\n        return chunk\n\n    async def read(self, n: int = -1) -> bytes:\n        if self._exception is not None:\n            raise self._exception\n\n        if not n:\n            return b\"\"\n","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/streams.py#L392-L428","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nline = await request.content.readline()  # default ~64KiB limit\n// after\nline = await request.content.readline(max_line_length=8 * 1024 * 1024)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from aiohttp.http_exceptions import LineTooLong\n\ntry:\n    line = await stream.readline()\nexcept LineTooLong as e:\n    # either raise the limit or switch to block reads\n    line = await stream.readany()","preventionTips":["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."],"tags":["streams","limits","http","security"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}