{"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":"validation","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/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/payload.py#L967-L1003","documentation":"Raised by AsyncIterablePayload.__init__ when the supplied value does not implement collections.abc.AsyncIterable. aiohttp uses this payload type to stream request/response bodies from an async producer, so it strictly requires an object with a working __aiter__/__anext__ protocol. Passing a plain list, a synchronous generator, bytes, or any non-async iterable triggers it. The error message reports the actual type via {type(value)!r} for diagnosis.","triggerScenarios":"Constructing AsyncIterablePayload(value) directly, or calling aiohttp.payload.get_payload()/payload_type() on an object that is not async iterable (e.g. a sync generator function, list, tuple, bytes, or a custom class lacking __aiter__). Also triggered indirectly by passing such an object as the data= argument to web.Response or client session methods when its class is not registered with PAYLOAD_REGISTRY.","commonSituations":"Developers migrating from requests/httpx who pass a sync generator to stream a body; passing a list of bytes chunks; using an async generator function object instead of the called coroutine (forgot parentheses); wrapping a sync file object instead of an aiohttp or aiofiles async reader.","solutions":["Pass an async iterable: an async generator function CALLED (e.g. async_gen()), an object implementing __aiter__, or an aiohttp.StreamReader.","If you only have a sync iterator, wrap it: async def gen(): for chunk in sync_iter: yield chunk, then pass gen().","For bytes/str already fully materialized, use BytesPayload (or just pass data=bytes) instead of AsyncIterablePayload.","Register a custom Payload subclass via PAYLOAD_REGISTRY.register(MyPayload, MyType) if you need first-class support for your type."],"exampleFix":"// before\nasync def producer():\n    for chunk in chunks:  # sync loop, not async\n        yield chunk\npayload = AsyncIterablePayload(producer())\n// after\nasync def producer():\n    for chunk in chunks:\n        yield chunk  # still works only if it is `async def`\npayload = AsyncIterablePayload(producer())\n# Or, for already-materialized bytes:\nfrom aiohttp import payload\np = payload.BytesPayload(b'data')","handlingStrategy":"type-guard","validationCode":"from collections.abc import AsyncIterable\n\ndef is_async_iterable(obj) -> bool:\n    return isinstance(obj, AsyncIterable)\n\n# before constructing:\nif not is_async_iterable(value):\n    raise TypeError(f'expected async iterable, got {type(value).__name__}')\npayload = AsyncIterablePayload(value)","typeGuard":"from collections.abc import AsyncIterable\nfrom typing import Any, TypeGuard\n\ndef is_async_iterable(obj: Any) -> TypeGuard[AsyncIterable[bytes]]:\n    return isinstance(obj, AsyncIterable)","tryCatchPattern":"from collections.abc import AsyncIterable\ntry:\n    payload = AsyncIterablePayload(value)\nexcept TypeError:\n    # fall back to materializing the body\n    payload = BytesPayload(bytes(value))","preventionTips":["Always pass async generators (called) or objects implementing __aiter__.","Register a custom Payload+type via PAYLOAD_REGISTRY for domain types.","Add a runtime isinstance(value, AsyncIterable) assert in test fixtures."],"tags":["payload","streaming","typeerror","typing"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}