AsyncPoeApi TypeError: object dict can't be used in 'await' expression"
I have a problem when I try to use asynchronous calls to the api.
import asyncio
from poe_api_wrapper import AsyncPoeApi
async def xx(client, row):
answer =
async for chunk in client.send_message("", message, chatId=):
return answer
async def process_batch(client, rows, batch_size=5):
tasks = []
for row in rows:
task = asyncio.create_task(xx(client, row))
tasks.append(task)
results = await asyncio.gather(*tasks)
return results
async def process_dataframe(df, batch_size=5):
client = await AsyncPoeApi(tokens=tokens).create()
results = await process_batch(client, batch_rows, batch_size)
async def main1():
batch_size = 1
await process_dataframe(df, batch_size)
asyncio.run(main1())
TypeError Traceback (most recent call last) Cell In[26], line 5 2 batch_size = 1 3 await process_dataframe(df, batch_size) ----> 5 asyncio.run(main1())
File d:\conda\lib\site-packages
est_asyncio.py:35, in _patch_asyncio.
File d:\conda\lib\site-packages
est_asyncio.py:90, in _patch_loop.
File d:\conda\lib\asyncio\futures.py:201, in Future.result(self) 199 self.__log_traceback = False 200 if self._exception is not None: --> 201 raise self._exception.with_traceback(self._exception_tb) 202 return self._result
File d:\conda\lib\asyncio\tasks.py:234, in Task.__step(failed resolving arguments) 232 result = coro.send(None) 233 else: --> 234 result = coro.throw(exc) 235 except StopIteration as exc: 236 if self._must_cancel: 237 # Task is cancelled right before coro stops.
Cell In[26], line 3, in main1() 1 async def main1(): 2 batch_size = 1 ----> 3 await process_dataframe(df, batch_size)
Cell In[17], line 41, in process_dataframe(df, batch_size) 38 batch_rows = df.iloc[batch_start:batch_end].to_dict('records') 40 # try: ---> 41 results = await process_batch(client, batch_rows, batch_size) 43 for idx, result in enumerate(results): 44 df_idx = batch_start + idx
Cell In[17], line 20, in process_batch(client, rows, batch_size) 18 task = asyncio.create_task(translate(client, row)) 19 tasks.append(task) ---> 20 results = await asyncio.gather(*tasks) 21 return results
File d:\conda\lib\asyncio\tasks.py:304, in Task.__wakeup(self, future) 302 def __wakeup(self, future): 303 try: --> 304 future.result() 305 except BaseException as exc: 306 # This may also be a cancellation. 307 self.__step(exc)
File d:\conda\lib\asyncio\tasks.py:232, in Task.__step(failed resolving arguments)
228 try:
229 if exc is None:
230 # We use the send method directly, because coroutines
231 # don't have __iter__ and __next__ methods.
--> 232 result = coro.send(None)
233 else:
234 result = coro.throw(exc)
Cell In[17], line 9, in translate(client, row) 8 answer = '' ----> 9 async for chunk in client.send_message("", message, chatId=):
File d:\conda\lib\site-packages\poe_api_wrapper\async_api.py:930, in AsyncPoeApi.send_message(self, bot, message, chatId, chatCode, msgPrice, file_path, suggest_replies, timeout) 926 yield response 928 last_text = response["text"] --> 930 await self.delete_queues(chatId) 931 self.retry_attempts = 3
File d:\conda\lib\site-packages\poe_api_wrapper\async_api.py:384, in AsyncPoeApi.delete_queues(self, chatId) 382 while not self.message_queues[chatId].empty(): 383 try: --> 384 await self.message_queues[chatId].get_nowait() 385 except asyncio.QueueEmpty: 386 pass
TypeError: object dict can't be used in 'await' expression"