Текст ошибки:
2021-05-13 22:12:28,079 (util.py:68 PollingThread) ERROR - TeleBot: "TypeError occurred, args=('first argument must be string or compiled pattern',)
Traceback (most recent call last):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
task(*args, **kwargs)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 286, in __retrieve_updates
self.process_new_updates(updates)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 332, in process_new_updates
self.process_new_messages(new_messages)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 358, in process_new_messages
self._notify_command_handlers(self.message_handlers, new_messages)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2028, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 1996, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2017, in _test_filter
return test_cases.get(message_filter, lambda msg: False)(message)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2012, in
'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text, re.IGNORECASE),
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 201, in search
return _compile(pattern, flags).search(string)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 303, in _compile
raise TypeError("first argument must be string or compiled pattern")
TypeError: first argument must be string or compiled pattern
"
Traceback (most recent call last):
File "d:/code/github.com/MIKHANGO/inedubots/wikipediabot/bot.py", line 101, in
client.polling(none_stop=True, interval=0)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 427, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 450, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 81, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\six.py", line 703, in reraise
raise value
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
task(*args, **kwargs)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 286, in __retrieve_updates
self.process_new_updates(updates)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 332, in process_new_updates
self.process_new_messages(new_messages)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 358, in process_new_messages
self._notify_command_handlers(self.message_handlers, new_messages)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2028, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 1996, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2017, in _test_filter
return test_cases.get(message_filter, lambda msg: False)(message)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 2012, in
'regexp': lambda msg: msg.content_type == 'text' and re.search(filter_value, msg.text, re.IGNORECASE),
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 201, in search
return _compile(pattern, flags).search(string)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 303, in _compile
raise TypeError("first argument must be string or compiled pattern")
TypeError: first argument must be string or compiled pattern
Ругается на строку client.polling(none_stop=True, interval=0)
# import нужных библиотек
import telebot
# import config
import wikipedia
from config import TOKEN
from telebot import types
# объявляем переменные
search = 'Поиск информации'
about = '❗️О сетке ботов inedubots❗️'
support = 'Поддержать'
rus = 'Русский язык поиска'
eng = 'Английский язык поиска'
enter = 'Введите запрос для поиска'
about_reaction = '❗️В сетку ботов входят боты: @rubdollarbot, @pernamebot, @wikiinedubot, @mathinedubot❗️ \n \
❗️Сетка ботов inedubots создана для привлечения инвестиций к боту @RuHelpEducationBot❗️'
diamond = '5599 0050 4579 2269'
set_red = 'Установлено'
set_orange = 'Установлено'
change_language_message = 'Смените язык'
bad_wiki_request_message = 'Такого запроса нету в википедии!'
bad_request_message = 'Несуществущий запрос!'
hello_message = 'Добро пожаловать, {0.first_name}!\n \
Я - <b>{1.first_name}</b>, бот созданный MIKHAN_GO для поиска информации в википедии)'
# берём токен из файла
client = telebot.TeleBot(TOKEN)
# команда старта бота
@client.message_handler(commands = ['start'])
def hello(message):
# отправляем стикер
hello = open('static/welcome.webp', 'rb')
client.send_sticker(message.chat.id, hello)
# добавляем клавиатуру к сообщению
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
search = types.KeyboardButton(search)
about = types.KeyboardButton(about)
support = types.KeyboardButton(support)
rus = types.KeyboardButton(rus)
eng = types.KeyboardButton(eng)
markup.add(search, about, support, rus, eng)
# отправляем сообщение с прикреплённой клавиатурой, приветствуя пользователя по никнейму
client.send_message(message.chat.id, hello_message.format(message.from_user,
client.get_me()), parse_mode='html', reply_markup=markup)
def search_wikipedia(message):
# выводим запрос поиска в википедии
try:
client.send_message(message.chat.id, 'Вот результат поиска вашего запроса в википедии: '
+ wikipedia.summary(message.text))
# иначе если ошибка подключения пишем о смене языка
except ConnectionError:
client.send_message(message.chat.id, change_language_message)
except:
client.send_message(message.chat.id, bad_wiki_request_message)
# search
@client.message_handler(regexp=search)
def search(message):
client.send_message(message.chat.id, enter)
client.register_next_step_handler(message, search_wikipedia)
# about
@client.message_handler(regexp=search)
def about(message):
client.send_message(message.chat.id, about_reaction)
# support
@client.message_handler(regexp=support)
def about(message):
client.send_message(message.chat.id, diamond)
# rus
@client.message_handler(regexp=search)
def about(message):
client.send_message(message.chat.id, set_red)
wikipedia.set_lang('ru')
#eng
@client.message_handler(regexp=search)
def about(message):
client.send_message(message.chat.id, set_orange)
wikipedia.set_lang('en')
# иначе
@client.message_handler(content_types = ['text'])
def answer(message):
client.send_message(message.chat.id, bad_request_message)
# запускаем бота
if __name__ == '__main__':
# устанавливаем русский язык поиска (по умолчанию)
wikipedia.set_lang('ru')
client.polling(none_stop=True, interval=0)