Пишу простого бота для телеграмма, выходит ошибка:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=MessageNotModi
fied('Message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message')>
Traceback (most recent call last):
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\achub\OneDrive\Рабочий стол\Python\telegram-bot\main.py", line 35, in start_handler
await msg.edit_text(f'{name}: <b>{price}</b> ' + '\n' + f'Кол-во обновлений было: {r+1}')
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\types\message.py", line 2892, in edit_text
return await self.bot.edit_message_text(
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\bot\bot.py", line 2990, in edit_message_text
result = await self.request(api.Methods.EDIT_MESSAGE_TEXT, payload)
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\bot\base.py", line 236, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\bot\api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\bot\api.py", line 115, in check_result
exceptions.BadRequest.detect(description)
File "C:\Users\achub\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\utils\exceptions.py", line 140, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.MessageNotModified: Message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message
Код бота:
import fake_useragent
from aiogram import Bot, Dispatcher, executor, types
import asyncio
import requests
from bs4 import BeautifulSoup as bs
import time
TOKEN = '5856432472:AAHbqiT-jVHjNarbFHFlsmuqxCP0KINJvCc'
bot = Bot(token=TOKEN, parse_mode="HTML")
dp = Dispatcher(bot=bot)
user = fake_useragent.UserAgent().random
headers = {'useragent': user}
url = 'https://coinmarketcap.com/currencies/bitcoin/'
response = requests.get(url, headers=headers)
soup = bs(response.text, 'lxml')
print(response.status_code)
name = soup.find('h1', class_='priceHeading').text
price = soup.find('div', class_='priceValue').text.replace('$', '').replace(',', '')
print(name + ': ' + price)
i = 0
@dp.message_handler(commands=['start'])
async def start_handler(message: types.Message):
user_name = message.from_user.first_name
await bot.send_message(message.from_user.id, f'Привет, <b>{user_name}</b>')
msg = await bot.send_message(message.from_user.id, f'{name}: <b>{float(price)}</b>')
while True:
await msg.edit_text(f'{name}: <b>{price}</b> ' + '\n' + f'Кол-во обновлений было: {i+1}')
asyncio.sleep(15)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)