исправь оишбку INFO:apscheduler.scheduler:Scheduler started…
- User
исправь оишбку INFO:apscheduler.scheduler:Scheduler started ERROR:telegram.ext.dispatcher:No error handlers are registered, logging exception. Traceback (most recent call last): File "C:\Users\home\PycharmProjects\витрина1\venv\lib\site-packages\telegram\ext\dispatcher.py", line 425, in process_update handler.handle_update(update, self, check, context) File "C:\Users\home\PycharmProjects\витрина1\venv\lib\site-packages\telegram\ext\handler.py", line 145, in handle_update return self.callback(update, context) File "C:\Users\home\PycharmProjects\витрина1\main.py", line 62, in show_product index = int(data[1]) IndexError: list index out of range в коде import logging import re import sqlite3 from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext import telegram
logging.basicConfig(level=logging.INFO) bot = telegram.Bot(token='6143413294:AAG_0lYsev83l0FaB5rqPdpYQPsHZPLEewI') API_TOKEN = '6143413294:AAG_0lYsev83l0FaB5rqPdpYQPsHZPLEewI'
def start(update: Update, context: CallbackContext): keyboard = [ [InlineKeyboardButton('Кроссовки', callback_data='category_items')], [InlineKeyboardButton('Верхняя одежда', callback_data='category_items1')], [InlineKeyboardButton('Аксессуары', callback_data='category_items2')], ] reply_markup = InlineKeyboardMarkup(keyboard)
if update.message: update.message.reply_text('Выберите категорию:', reply_markup=reply_markup) else: query = update.callback_query query.answer() query.edit_message_text('Выберите категорию:', reply_markup=reply_markup)def show_items(update: Update, context: CallbackContext, category): query = update.callback_query query.answer()
conn = sqlite3.connect('kross.db') c = conn.cursor() c.execute(f'SELECT name FROM {category}') items = c.fetchall() keyboard = [ [InlineKeyboardButton(items[i][0], callback_data=f"{category}{i}") for i in range(min(4, len(items)))] ] if len(items) > 4: keyboard.append([ InlineKeyboardButton('Вперед', callback_data=f'next_0_4{category}') ]) reply_markup = InlineKeyboardMarkup(keyboard) query.edit_message_text('Выберите товар:', reply_markup=reply_markup)def category_callback(update: Update, context: CallbackContext): query = update.callback_query match = re.match(r'category_(items[0-9]*)', query.data) category = match.group(1) show_items(update, context, category)
def show_product(update: Update, context: CallbackContext): query = update.callback_query data = query.data.split('_') category = data[0] index = int(data[1])
conn = sqlite3.connect('kross.db') c = conn.cursor() c.execute(f'SELECT name, size, info, price, photo_link FROM {category}') items = c.fetchall() item = items[index] text = f'Название: {item[0]}\nРазмер: {item[1]}\nОписание: {item[2]}\nЦена: {item[3]}\nСсылка на фото: {item[4]}' keyboard = [ [InlineKeyboardButton('Вернуться', callback_data=f'back_{category}')] ] reply_markup = InlineKeyboardMarkup(keyboard) query.answer() query.edit_message_text(text=text, reply_markup=reply_markup) - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.