AttributeError("'CallbackQuery' object has no attribute 'content_type'") pyTelegramBotApi
python3/PyTelegramBotAPI.
Здравствуйте, столкнулся с ошибкой, решаю уже ~час ничего не помогает:
AttributeError("'CallbackQuery' object has no attribute 'content_type'")
В кратце о логике проекта -
Есть кнопка 'Главное', которая вызывает функцию 'process_allcourse', передает ей параметры call,me.
Функция 'process_allcourse' выводит список курсов и кнопки '<','>' при нажатие на них они посылаю calldata, он в свою очередь вызывает 'process_allcourse' с другими параметрами (Так сказать пагинация)
Не сильно понимаю в чем ошибка, буду рад вашей помощи!
Название переменных не совсем корректены, за это прошу прощения.
def process_allcourse(call,me):
global x
if call.content_type == 'text':
x = 0
else:
if me == '>':
x+=1
elif me == '<':
x-=1
else:
print('error')
with sql.connect("database.db") as db:
curs = db.cursor()
curs.execute("SELECT * FROM courses")
result_par = curs.fetchall()
courses = result_par
course = courses[x]
markups = types.InlineKeyboardMarkup()
BCourse= types.InlineKeyboardButton('Перейти к курсу',callback_data=str(course))
Bback= types.InlineKeyboardButton('<',callback_data='<')
Bmid= types.InlineKeyboardButton("Курс {0} из {1}.".format(x,len(courses)),callback_data='dsa')
Bnext= types.InlineKeyboardButton('>',callback_data='>')
markups.add(BCourse)
markups.add(Bback,Bmid,Bnext)
if call.content_type == 'text':
bot.send_photo(call.chat.id, open('1.jpg', 'rb'),caption=course[1],reply_markup=markups)
else:
bot.send_photo(call.message.chat.id, open('1.jpg','rb'),caption=course[1],reply_markup=markups)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Главное")
item2 = types.KeyboardButton("Поиск")
item3 = types.KeyboardButton("Каталог")
markup.add(item1)
markup.add(item2, item3)
bot.send_message(message.chat.id, "Добро пожаловать, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот созданный чтобы быть подопытным кроликом.".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'Главное':
me = '132'# test
process_allcourse(message,me)
@bot.callback_query_handler(func=lambda call: True) #CALL DATA
def callback_inline(call):
try:
if call.message:
if call.data == '>' or '<':
me = call.data
process_allcourse(call,me)
else:
bot.send_message(chat_id=call.message.chat.id, text=str(call.data))