import asyncio
import aiohttp
from bs4 import BeautifulSoup
import telebot
import os
import time
import tracemalloc
tracemalloc.start()
bot = telebot.TeleBot('***')
@bot.message_handler(commands=['start'])
def start(message):
bot.reply_to(message, 'Введите номер авто для поиска информации.')
@bot.message_handler(func=lambda message: True)
async def search(message):
await search(message)
a = message.text
url = "https://sicmt.ru/fgis-taksi"
querystring = {"type":"car","filters[regNumTS]":a,"filters[licenseNumber]":"","filters[region]":""}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
}
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, params=querystring, headers=headers) as response:
response.raise_for_status()
soup = BeautifulSoup(await response.text(), "html.parser")
try:
id = soup.find('td', class_='hide-on-desktop').find('a').get('href')
except:
bot.reply_to(message, "Еще не готово, введите номер авто.")
return
mod_id = id.split('=')
url = "https://sicmt.ru/fgis-taksi/pdf"
querystring = {"type":"car","id": mod_id[1]}
async with session.get(url, params=querystring, headers=headers) as response:
response.raise_for_status()
with open(f"{a}.pdf", 'wb') as f:
f.write(await response.read())
with open(f"{a}.pdf", 'rb') as f:
bot.send_document(message.chat.id, f)
bot.reply_to(message, "Готово!")
await asyncio.sleep(300)
os.remove(f"{a}.pdf")
except aiohttp.ClientError as e:
print("Ошибка при выполнении запроса:", e)
await asyncio.sleep(5)
await search(message)
return
while True:
try:
bot.polling()
except Exception as e:
print("Ошибка при выполнении бота:", e)
time.sleep(5)
при запуске на сервере выдает ошибку
/usr/local/lib/python3.10/dist-packages/telebot/util.py:90: RuntimeWarning: coroutine 'handle_message' was never awaited
task(*args, **kwargs)
Object allocated at (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/telebot/__init__.py", lineno 6801
result = handler['function'](message)
Что я не правильно сделал и не увидел?