I wrote a program on python using aiogram, now I'm refactoring the code. There was a problem that I cannot take out a piece of code from do_something func to the get_task_info func:
async def get_task_info(task_info, message: types.Message):
if message.content_type == 'text':
task_info.append(message.text)
elif message.content_type == 'photo':
task_info.extend([str(message.caption),
await message.photo[-1].get_url()])
elif message.content_type == 'document':
task_info.extend([str(message.caption),
await message.document.get_url()])
return task_info
@dp.message_handler(state=Order.some_state)
async def do_something(message: types.Message, state: FSMContext):
data = await state.get_data()
task_info = data.get('task_info', list())
task_info = get_task_info(task_info, message)
await state.update_data(task_info=task_info)
await message.answer('Done')
And when I try so there is an exception:
ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\dispatcher.py:331> exception=TypeError("can't pickle coroutine objects")>
Traceback (most recent call last):
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 339, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 194, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 214, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "F:\Telegram\handlers\order.py", line 110, in commit_task
data = await state.get_data()
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\dispatcher\storage.py", line 298, in get_data
return await self.storage.get_data(chat=self.chat, user=self.user, default=default)
File "C:\Users\HP\miniconda3\lib\site-packages\aiogram\contrib\fsm_storage\memory.py", line 45, in get_data
return copy.deepcopy(self.data[chat][user]['data'])
File "C:\Users\HP\miniconda3\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\HP\miniconda3\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\HP\miniconda3\lib\copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: can't pickle coroutine objects
Process finished with exit code -1
What should I do?