In my Django channels (websocket) i want to return data of for loop every time it gets a values using yield.if text_data:
received_message = json.loads(text_data)# Yield in Async function of Django channelsif received_message.get('open_box', False): rounds = await self.get_boxes_from_database(received_message) for r in rounds: response_data = await self.open_box_operation(received_message, r) data = self.send_group_notification({'type': 'OPEN-BOX', 'data':response_data}) yield data
but i am getting error
ERROR 2024-01-24 07:32:01,403 server Exception inside application: object async_generator can't be used in 'await' expression Traceback (most recent call last): File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\django\contrib\staticfiles\handlers.py", line 101, in __call__ return await self.application(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\routing.py", line 62, in __call__ return await application(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\sessions.py", line 47, in __call__ return await self.inner(dict(scope, cookies=cookies), receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\sessions.py", line 263, in __call__ return await self.inner(wrapper.scope, receive, wrapper.send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\auth.py", line 185, in __call__ return await super().__call__(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\middleware.py", line 24, in __call__ return await self.inner(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\routing.py", line 116, in __call__ return await application( ^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\consumer.py", line 94, in app return await consumer(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\consumer.py", line 58, in __call__ await await_many_dispatch( File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\utils.py", line 50, in await_many_dispatch await dispatch(result) File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\consumer.py", line 73, in dispatch await handler(message) File "g:\OFFICE DATA\rilla box\rillabox\.venv\Lib\site-packages\channels\generic\websocket.py", line 194, in websocket_receive await self.receive(text_data=message["text"]) TypeError: object async_generator can't be used in 'await' expression