{"id":"24859c8172b3e955","repo":"aio-libs/aiohttp","slug":"not-enough-data-to-satisfy-transfer-length-header","errorCode":null,"errorMessage":"Not enough data to satisfy transfer length header.","messagePattern":"Not enough data to satisfy transfer length header\\.","errorType":"http","errorClass":"TransferEncodingError","httpStatus":400,"severity":"error","filePath":"aiohttp/http_parser.py","lineNumber":923,"sourceCode":"    def feed_eof(self) -> None:\n        if self._type == ParseState.PARSE_UNTIL_EOF:\n            self._eof_pending = True\n            while self._more_data_available:\n                if self._paused:\n                    self._paused = False\n                    return  # Will resume via feed_data(b\"\") later\n                self._more_data_available = self.payload.feed_data(b\"\")\n            self.payload.feed_eof()\n            self.done = True\n            self._eof_pending = False\n        elif self._type == ParseState.PARSE_LENGTH:\n            received = self._length_expected - self._length\n            raise ContentLengthError(\n                f\"Not enough data to satisfy content length header \"\n                f\"(received {received} of {self._length_expected} bytes).\"\n            )\n        elif self._type == ParseState.PARSE_CHUNKED:\n            raise TransferEncodingError(\n                \"Not enough data to satisfy transfer length header.\"\n            )\n\n    def feed_data(\n        self, chunk: bytes, SEP: _SEP = b\"\\r\\n\", CHUNK_EXT: bytes = b\";\"\n    ) -> tuple[PayloadState, bytes]:\n        \"\"\"Receive a chunk of data to process.\n\n        Return:\n            PayloadState - The current state of payload processing.\n                           This function may be called with empty bytes after returning\n                           PAYLOAD_HAS_PENDING_INPUT to continue processing after a pause.\n            bytes - If payload is complete, this is the unconsumed bytes intended for the\n                    next message/payload, b\"\" otherwise.\n        \"\"\"\n        # Read specified amount of bytes\n        if self._type == ParseState.PARSE_LENGTH:\n            if self._chunk_tail:","sourceCodeStart":905,"sourceCodeEnd":941,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/http_parser.py#L905-L941","documentation":"TransferEncodingError raised in feed_eof when a chunked-encoded body stream ends without the terminating zero-length chunk. In PARSE_CHUNKED mode, feed_eof means EOF arrived before the `0\\r\\n\\r\\n` terminator.","triggerScenarios":"Server uses Transfer-Encoding: chunked but the connection closes before sending the final zero-size chunk. feed_eof() in the PARSE_CHUNKED branch raises TransferEncodingError.","commonSituations":"Server crash mid-stream; proxy cutting a long chunked response; SSE/streaming endpoint that never sends a terminator; broken upstream that omits the final chunk.","solutions":["Confirm the upstream sends the terminating `0\\r\\n\\r\\n` for chunked bodies.","Check for intermediary timeouts killing the stream.","Handle the error on the read side and close the response cleanly.","Retry with a non-streaming request to isolate."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from aiohttp.http_exceptions import TransferEncodingError\ntry:\n    async for data in resp.content.iter_chunked(1024):\n        ...\nexcept TransferEncodingError:\n    log.warning('chunked stream truncated')","preventionTips":["Don't assume streaming endpoints always terminate cleanly.","Wrap streaming reads in error handling."],"tags":["http","parser","payload","chunked","transfer-encoding","truncated"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}