I created the bot using aiogram 3.4.1 and it worked well. I left the project for two months and returned to it recently. When calling any menu, the bot gives an error:
aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't parse entities: Unsupported start tag "" at byte offset
Next are lines about dispatcher errors:
Traceback (most recent call last):
File "/Users/.../lib/python3.10/site-packages/aiogram/dispatcher/dispatcher.py", line 309, in _process_update
response = await self.feed_update(bot, update, **kwargs)
File "/Users/.../lib/python3.10/site-packages/aiogram/dispatcher/dispatcher.py", line 158, in feed_update
response = await self.update.wrap_outer_middleware(
File "/Users/.../lib/python3.10/site-packages/aiogram/dispatcher/middlewares/error.py", line 25, in __call__
return await handler(event, data)
... and more
I have tried other versions of aiogram. I changed the quotes in the menu item definitions to single ones. Nothing helped. Search didn’t help me too.
Please help me to understand what the problem is it, because the bot worked well before, and I don’t want to completely rewrite it.
main.py
from aiogram import Bot, Dispatcher
from aiogram.enums import ParseMode
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.client.bot import DefaultBotProperties
async def main() -> None:
bot = Bot(API_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
dp = Dispatcher(storage=MemoryStorage())
dp.include_router(common.router)
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
common.py
from aiogram import F, Router
from aiogram.filters import Command
from aiogram.fsm.context import FSMContext
from aiogram.types import Message
from handlers.keyboard import start_keyboard
from handlers import add_hand
from handlers import manage_hand
from handlers import count_hand
from handlers import service_hand
from config import admins
router = Router()
router.include_router(add_hand.router)
router.include_router(manage_hand.router)
router.include_router(count_hand.router)
router.include_router(service_hand.router)
@router.message(F.from_user.id.in_(admins), Command(commands=["start"]))
async def cmd(message: Message, state: FSMContext):
await state.clear()
keyboard=start_keyboard()
await message.answer(
text="Choose action",
reply_markup=keyboard
)
@router.message(Command(commands=["cancel"]))
@router.message(F.text.lower() == "back")
async def cmd(message: Message, state: FSMContext):
await state.clear()
keyboard=start_keyboard()
await message.answer(
text="Choose action",
reply_markup=keyboard
)
keyboard.py
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
def make_row_keyboard(items: list[str]) -> ReplyKeyboardMarkup:
row = [KeyboardButton(text=item) for item in items]
return ReplyKeyboardMarkup(keyboard=[row], resize_keyboard=True)
def start_keyboard():
kb = [
[
KeyboardButton(text="Add"),
KeyboardButton(text='Manage'),
KeyboardButton(text="Count"),
KeyboardButton(text="Service")
],
]
keyboard = ReplyKeyboardMarkup(
keyboard=kb,
resize_keyboard=True,
input_field_placeholder="Choose action"
)
return (keyboard)
- Check the ParseMode Settings
Make sure you’re setting the correct ParseMode. You’re already setting it to ParseMode.HTML in your main.py, but if there are any issues with the HTML tags in your message text, the bot will throw this error.
Check for missing or incorrect HTML tags in the message.answer() function. Even a single misplaced tag could cause this error.
For example, if you are using a string with unsupported HTML tags, that might be the problem. Verify that all HTML tags in your messages are correct and supported by Telegram.
Rashmi Panchal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1