Task exception was never retrieved future:
вылезает даная ошибка при выполнении запроса в телеграм бота в инлайн режиме.
Суть: есть бот на aiogram который выдает гороскоп на сегодня при вводе юзернейма бота что-то в стиле @bot aries
код:
import re
from aiogram.types import InputTextMessageContent, InlineQuery, InlineQueryResultArticle
from aiogram.utils.emoji import emojize
from aiogram.utils.markdown import hbold
from groups.horo_parser import memory_of_horo
from loader import dp, bot
some_emoji = {
'овен': 'aries',
'телець': 'taurus',
'близнюки': 'gemini',
'рак': 'cancer',
'лев': 'lion',
'діва': 'virgo',
'терези': 'libra',
'скорпіон': 'scorpio',
'стрілець': 'sagittarius',
'козеріг': 'capricorn',
'водолій': 'aquarius',
'риби': 'pisces',
}
def parser():
dict_of_site = memory_of_horo()
return dict_of_site
@dp.inline_handler()
async def inline_echo(inline_query: InlineQuery):
text = inline_query.query
text = text.lower()
pattern = re.compile(r"\w+")
try:
intermed_progress = re.match(pattern, text)
some_var = intermed_progress.group()
except AttributeError as ex:
return
dict_of_site = parser()
result = str((await dict_of_site)[f'{some_var}'])
result = result.replace("[", "")
result = result.replace("]", "")
result = result.replace("'", "")
upper_text = text.upper()
fin_res = hbold(upper_text)
emojized = ''
if some_var in some_emoji:
emozi = some_emoji[f"{some_var}"]
emojized = emojize(f":{emozi}:")
ost_result = f"{fin_res}{emojized}\n{result}"
input_content = InputTextMessageContent(ost_result)
item = InlineQueryResultArticle(
id=1,
#??????
title="Гороскоп на сьогодні",
input_message_content=input_content,
)
await bot.answer_inline_query(inline_query.id, results=[item], cache_time=300)
и есть к нему парсер
import requests
from bs4 import BeautifulSoup
from loader import schreduler
horo_ukr = ["овен", "телець", "близнюки", "рак", "лев", "діва", "терези", "скорпіон", "стрілець", "козеріг",
"водолій", "риби"]
horo = ['aries', 'taurus', 'gemini', 'cancer', 'lion', 'virgo', 'libra', 'scorpio', 'sagittarius', 'capricorn',
'aquarius', 'pisces']
def gg():
dict_of_site = {}
i = -1
for items in horo:
i += 1
url = f'https://orakul.com/horoscope/astrologic/general/{items}/today.html'
res = requests.get(url).text
soup = BeautifulSoup(res, "lxml")
page = soup.find('div', class_='horoBlock').find('p').text
page = page.replace("\r", "")
page = page.replace("\n", "")
page = page.strip()
dict_of_site[horo_ukr[i]] = [page]
return dict_of_site
async def memory_of_horo():
some_new_var = gg()
return some_new_var
def some_new_job():
scheduler.add_job(memory_of_horo, 'cron', day_of_week="mon-sun", hour=1, minute=0)
так вот
при запросе знака зодиака длинной больше чем в 3 символа страдает рантайм и вывод не происходит.
но если ввести допустим @bot рак то бот выдаст результат.
В чем ошибка?
заранее спасибо за помощь
вся ошибка:
base_events.py [LINE:1707] #ERROR [2021-06-15 15:24:18,928] Task exception was never retrieved
future: <Task finished name='Task-18' coro=<Dispatcher._process_polling_updates() done, defined at /home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/dispatcher.py:380> exception=KeyError('козері')>
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/dispatcher.py", line 388, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "/home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/dispatcher.py", line 225, in process_updates
return await asyncio.gather(*tasks)
File "/home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/dispatcher.py", line 263, in process_update
return await self.inline_query_handlers.notify(update.inline_query)
File "/home/ubuntu/.local/lib/python3.8/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/ubuntu/telegrambot/groups/horo.py", line 40, in inline_echo
result = str((await dict_of_site)[f'{some_var}'])
KeyError: 'козері'