Иногда при генерации пароля в тг боте вылезает ошибка в терминал
Версия aiogram 3.2.0
Ошибка такая: aiogram.exceptions.TelegramBadRequest: Telegram server says - Bad Request: can't parse entities: Unsupported start tag "maox{d?%l*jybqi,$dbr;3!k:)[p wn@i</code" at byte offset 46
import asyncio
import random
from aiogram import Bot, Dispatcher, types
from aiogram.enums import ParseMode
from aiogram.filters import Command, CommandStart
from aiogram.types import Message
from aiogram.client.session.aiohttp import AiohttpSession
TOKEN = "*******************************************"
dp = Dispatcher()
@dp.message(CommandStart())
async def command_start_handler(message: Message):
await message.answer("Hello? I am a bot that generates random passwords? To get started, check out the commands?\n/start - restart bot?\n/generate <b>PASSWORD_LENGTH</b> - creates a unique, random password? with a user-specified length.\n/help - shows all commands❓")
@dp.message(Command("generate"))
async def command_generate_handler(message: Message):
if len(message.text.split()) == 1:
# Видаємо помилку
await message.answer("You must specify the password length⚠️\nExample: <code>/generate 12</code>")
return
else:
# Запитуємо довжину пароля
try:
length = int(message.text.split()[1])
except ValueError:
# Видаємо помилку
await message.answer("The password length must be an integer number⚠️")
return
if length < 8 or length > 48:
# Видаваємо помилку
await message.answer("The password length must be specified in the range from 8 to 48⚠️")
else:
# Генеруємо пароль
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "0123456789"
symbols = "~`!@#$%^&*()_-+={[}]|:;<,>.?/"
string = lower + upper + numbers + symbols
password = "".join(random.sample(string, length))
# Відправляємо пароль користувачу
await message.answer("Here is your new password: " + f"<code>{password}</code>", parse_mode = ParseMode.HTML)
@dp.message(Command("help"))
async def command_help_handler(message: Message):
await message.answer("/start - restart bot?\n/generate <b>PASSWORD_LENGTH</b> - creates a unique, random password? with a user-specified length.\n/help - shows all commands❓")
async def main():
session = AiohttpSession(proxy="http://proxy.server:3128")
bot = Bot(TOKEN, session = session, parse_mode = ParseMode.HTML)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())