{"record":{"id":"d67425664e5566f3","repo":"aio-libs/aiohttp","slug":"value-argument-must-support-collections-abc-asynci","errorCode":null,"errorMessage":"value argument must support collections.abc.AsyncIterable interface, got {type(value)!r}","messagePattern":"value argument must support collections\\.abc\\.AsyncIterable interface, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"aiohttp/payload.py","lineNumber":985,"sourceCode":"    ) -> None:\n        super().__init__(\n            dumps(value),\n            content_type=content_type,\n            *args,\n            **kwargs,\n        )\n\n\nclass AsyncIterablePayload(Payload):\n    _iter: AsyncIterator[bytes] | None = None\n    _value: AsyncIterable[bytes]\n    _cached_chunks: list[bytes] | None = None\n    # _consumed stays False to allow reuse with cached content\n    _autoclose = True  # Iterator doesn't need explicit closing\n\n    def __init__(self, value: AsyncIterable[bytes], *args: Any, **kwargs: Any) -> None:\n        if not isinstance(value, AsyncIterable):\n            raise TypeError(\n                \"value argument must support \"\n                \"collections.abc.AsyncIterable interface, \"\n                f\"got {type(value)!r}\"\n            )\n\n        if \"content_type\" not in kwargs:\n            kwargs[\"content_type\"] = \"application/octet-stream\"\n\n        super().__init__(value, *args, **kwargs)\n\n        self._iter = value.__aiter__()\n\n    async def write(self, writer: AbstractStreamWriter) -> None:\n        \"\"\"\n        Write the entire async iterable payload to the writer stream.\n\n        Args:\n            writer: An AbstractStreamWriter instance that handles the actual writing","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/payload.py#L967-L1003","documentation":"Raised by AsyncIterablePayload.__init__ when value does not implement collections.abc.AsyncIterable. This payload class streams a body from an async source, so a plain iterable, a sync generator, a list, or a file object is rejected. The check uses isinstance against AsyncIterable, so even an object with __iter__ but no __aiter__ fails.","triggerScenarios":"Constructing AsyncIterablePayload([b'a', b'b']) with a list; passing a sync generator (def gen(): yield b'x') instead of an async generator (async def gen(): yield b'x'); passing a file object opened with open() instead of aiofiles.","commonSituations":"Streaming an uploaded file using blocking open(); using a generator function without async; confusing IterablePayload (sync) with AsyncIterablePayload (async).","solutions":["Use an async generator: async def gen(): yield chunk; AsyncIterablePayload(gen()).","For a sync iterable/list, use the sync IterablePayload or aiohttp's stream-based helpers instead.","Open files with aiofiles and iterate the async file object so it is AsyncIterable."],"exampleFix":"# before\ndef gen():\n    yield b'chunk'\npayload = AsyncIterablePayload(gen())\n\n# after\nasync def gen():\n    yield b'chunk'\npayload = AsyncIterablePayload(gen())","handlingStrategy":"type-guard","validationCode":"from collections.abc import AsyncIterable\nif not isinstance(value, AsyncIterable):\n    raise TypeError('value must be async-iterable')\npayload = AsyncIterablePayload(value)","typeGuard":"from collections.abc import AsyncIterable\ndef is_async_iterable(v) -> bool:\n    return isinstance(v, AsyncIterable)","tryCatchPattern":"try:\n    payload = AsyncIterablePayload(value)\nexcept TypeError:\n    # fall back to wrapping a sync iterable as an async generator\n    async def _wrap():\n        for chunk in value:\n            yield chunk\n    payload = AsyncIterablePayload(_wrap())","preventionTips":["Define streaming sources as async generators (async def + yield).","Use aiofiles (not open()) for file streaming payloads.","Confirm the source has __aiter__ before constructing AsyncIterablePayload."],"tags":["payload","async","iterable","type-error"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}