Size: a a a

2017 November 07

m

m0cesta in aiogram [ru]
А я пытался сохранить объект :)
источник

AR

Alex RootJunior in aiogram [ru]
m0cesta
Кстати пару дней назад часов 5 дебажил неуловимую ошибку, которая появлялась из-за того что storage не может хранить что-либо кроме чисел и строк. Не сразу просёк это
Эм?.. там json же
источник

AR

Alex RootJunior in aiogram [ru]
m0cesta
А я пытался сохранить объект :)
А, лол
источник

m

m0cesta in aiogram [ru]
Да, я не правильно немного выразился. Я имел ввиду ничего кроме json
источник

AR

Alex RootJunior in aiogram [ru]
Можно попробовать json заменить на yaml, он умеет с объектами работать
источник

AR

Alex RootJunior in aiogram [ru]
Но может медленнее работать, ну или кривее
источник

OA

Oleg A. 🇷🇺 in aiogram [ru]
m0cesta
А я пытался сохранить объект :)
Так забери у объекта словарь и сохрани. А потом восстановишь в объект
источник

BE

Bogdan Evstratenko in aiogram [ru]
m0cesta
Да, я не правильно немного выразился. Я имел ввиду ничего кроме json
Про редиску речь идет?
источник
2017 November 08

AR

Alex RootJunior in aiogram [ru]
m0cesta
def keyboard(board, **kwargs):
   '''
   Получить разметку для клавиатуры aiogram из двумерного списка.
   '''
   board = [[KeyboardButton(button) for button in row] for row in board]
   return ReplyKeyboardMarkup(board, *kwargs)
а у тебя тут ошибочка
источник

AR

Alex RootJunior in aiogram [ru]
должно быть две звезды **
источник

AR

Alex RootJunior in aiogram [ru]
ибо kwargs - словарь, а ты его распаковываешь как список
источник
2017 November 10

m

m0cesta in aiogram [ru]
Alex RootJunior
ибо kwargs - словарь, а ты его распаковываешь как список
Да, виноват
источник

m

m0cesta in aiogram [ru]
Bogdan Evstratenko
Про редиску речь идет?
Угу
источник

m

m0cesta in aiogram [ru]
Обнаружил другую ошибку. Когда вызываю asyncio.gather получаю:
Task exception was never retrieved
future: <Task finished coro=<Dispatcher._process_pooling_updates() done, defined at /home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py:208> exception=TypeError('An asyncio.Future, a coroutine or an awaitable is required',)>
Traceback (most recent call last):
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 215, in _process_pooling_updates
   for response in await self.process_updates(updates):
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 103, in process_updates
   return await asyncio.gather(*tasks)
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 120, in process_update
   return await self.message_handlers.notify(update.message)
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/handler.py", line 42, in notify
   response = await handler(*args, **kwargs)
 File "src/fsm.py", line 337, in get_contacts_and_finish
   await profile_mailing(message)
 File "src/fsm.py", line 100, in profile_mailing
   return_exceptions=True
 File "/home/hector/Downloads/Python-3.6.3/Lib/asyncio/tasks.py", line 596, in gather
   fut = ensure_future(arg, loop=loop)
 File "/home/hector/Downloads/Python-3.6.3/Lib/asyncio/tasks.py", line 526, in ensure_future
   raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
TypeError: An asyncio.Future, a coroutine or an awaitable is required

Вот код:
    async def profile_mailing(message):
       state = dp.current_state(chat=message.chat.id,
                                user=message.from_user.id)
       data = await state.get_data()
       temp = open('res/texts/template_for_provider.txt').read()
       
       if type(data['location']) == int:
           location = 'См. геопозицию'
       else:
           location = data['location']
           
       if type(data['description']) == int:
           description = 'См. файл медиа'
       else:
           description = data['description']
       
       temp = temp.format(
           data['srvc'],
           description,
           location,
           data['contacts']
       )
       
       packages = [lambda recipient: bot.send_message(recipient, temp)]
       #profile_messages.append((recipient, mess.message_id))
       if type(data['description']) == int:
           packages.append(lambda recipient: bot.forward_message(
               recipient,
               message.chat.id,
               data['description']
           ))
       if type(data['location']) == int:
           packages.append(lambda recipient: bot.forward_message(
               recipient,
               message.chat.id,
               data['location']
           ))
       
       if data['srvc'] == BL.SRVC_UNDETECTED:
           recipients = [FEEDBACK_CHANNEL_CHAT_ID]
       else:
           recipients = BL.SERVICE_DISTRIBUTION[data['srvc']]
       
       for recipient in recipients:
           msgs = asyncio.gather(
               map(lambda f: f(recipient), packages),
               loop=loop,
               return_exceptions=True
           )
           profile_messages += [(recipient, msg.message_id) for msg in msgs]
           
       
       
       profile_messages += data.get('profile_messages', [])
       await state.update_data(profile_messages=profile_messages,
                               last_mailing_time=datetime.now().timestamp())
источник

m

m0cesta in aiogram [ru]
m0cesta
Обнаружил другую ошибку. Когда вызываю asyncio.gather получаю:
Task exception was never retrieved
future: <Task finished coro=<Dispatcher._process_pooling_updates() done, defined at /home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py:208> exception=TypeError('An asyncio.Future, a coroutine or an awaitable is required',)>
Traceback (most recent call last):
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 215, in _process_pooling_updates
   for response in await self.process_updates(updates):
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 103, in process_updates
   return await asyncio.gather(*tasks)
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/__init__.py", line 120, in process_update
   return await self.message_handlers.notify(update.message)
 File "/home/hector/Projects/aiogram_python_env/lib/python3.6/site-packages/aiogram-1.0.dev20171027172954-py3.6.egg/aiogram/dispatcher/handler.py", line 42, in notify
   response = await handler(*args, **kwargs)
 File "src/fsm.py", line 337, in get_contacts_and_finish
   await profile_mailing(message)
 File "src/fsm.py", line 100, in profile_mailing
   return_exceptions=True
 File "/home/hector/Downloads/Python-3.6.3/Lib/asyncio/tasks.py", line 596, in gather
   fut = ensure_future(arg, loop=loop)
 File "/home/hector/Downloads/Python-3.6.3/Lib/asyncio/tasks.py", line 526, in ensure_future
   raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
TypeError: An asyncio.Future, a coroutine or an awaitable is required

Вот код:
    async def profile_mailing(message):
       state = dp.current_state(chat=message.chat.id,
                                user=message.from_user.id)
       data = await state.get_data()
       temp = open('res/texts/template_for_provider.txt').read()
       
       if type(data['location']) == int:
           location = 'См. геопозицию'
       else:
           location = data['location']
           
       if type(data['description']) == int:
           description = 'См. файл медиа'
       else:
           description = data['description']
       
       temp = temp.format(
           data['srvc'],
           description,
           location,
           data['contacts']
       )
       
       packages = [lambda recipient: bot.send_message(recipient, temp)]
       #profile_messages.append((recipient, mess.message_id))
       if type(data['description']) == int:
           packages.append(lambda recipient: bot.forward_message(
               recipient,
               message.chat.id,
               data['description']
           ))
       if type(data['location']) == int:
           packages.append(lambda recipient: bot.forward_message(
               recipient,
               message.chat.id,
               data['location']
           ))
       
       if data['srvc'] == BL.SRVC_UNDETECTED:
           recipients = [FEEDBACK_CHANNEL_CHAT_ID]
       else:
           recipients = BL.SERVICE_DISTRIBUTION[data['srvc']]
       
       for recipient in recipients:
           msgs = asyncio.gather(
               map(lambda f: f(recipient), packages),
               loop=loop,
               return_exceptions=True
           )
           profile_messages += [(recipient, msg.message_id) for msg in msgs]
           
       
       
       profile_messages += data.get('profile_messages', [])
       await state.update_data(profile_messages=profile_messages,
                               last_mailing_time=datetime.now().timestamp())
Код лучше оставить здесь: https://kopy.io/byM4p
источник
2017 November 11

AR

Alex RootJunior in aiogram [ru]
m0cesta
Код лучше оставить здесь: https://kopy.io/byM4p
Ты лямбду пытаешься запустить как корутину, а это не поддерживается
источник

AR

Alex RootJunior in aiogram [ru]
источник

AR

Alex RootJunior in aiogram [ru]
m0cesta
Редиска
источник

m

m0cesta in aiogram [ru]
Нет, я сначала применяю лямбды к recipient
источник

m

m0cesta in aiogram [ru]
Alex RootJunior
Ты лямбду пытаешься запустить как корутину, а это не поддерживается
источник