IndentationError: unexpected unindent

Pomogite_pg_croki_goryat

Новичок
Пользователь
Дек 23, 2021
4
0
1
  1. Windows 10
  2. 3.10
  3. pyTelegramBotAP
  4. Python:
    import telebot
    import config
    import random
    
    from telebot import types
    
    bot = telebot.TeleBot(config.TOKEN)
    
    @bot.message_handler(content_types=['text'])
    def ms(message):
        bot.message_handler(content_types=['text', 'document', 'audio'])
        if message.text == "Привет":
            bot.send_message(message.from_user.id, "Привет, чем я могу тебе помочь?")
        elif message.text == "/help":
            bot.send_message(message.from_user.id, "Напиши привет")
        else:
            bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")
    
    bot.polling(none_stop=True, interval=0)
    
    name = '';
    surname = '';
    age = 0;
    @bot.message_handler(content_types=['text'])
    def start(message):
        if message.text == '/reg':
            bot.send_message(message.from_user.id, "Как тебя зовут?");
            bot.register_next_step_handler(message, get_name); #следующий шаг – функция get_name
        else:
            bot.send_message(message.from_user.id, 'Напиши /reg');
    
    def get_name(message): #получаем фамилию
        global name;
        name = message.text;
        bot.send_message(message.from_user.id, 'Какая у тебя фамилия?');
        bot.register_next_step_handler(message, get_surnme);
    
    def get_surname(message):
        global surname;
        surname = message.text;
        bot.send_message('Сколько тебе лет?');
        bot.register_next_step_handler(message, get_age);
    
    def get_age(message):
        global age;
        while age == 0: #проверяем что возраст изменился
            try:
                 age = int(message.text) #проверяем, что возраст введен корректно
            except Exception:
                 bot.send_message(message.from_user.id, 'Цифрами, пожалуйста');
                 bot.send_message(message.from_user.id, 'Тебе '+str(age)+' лет, тебя зовут '+name+' '+surname+'?')
    
    def get_age(message):
        global age;
        while age == 0: #проверяем что возраст изменился
            try:
                 age = int(message.text) #проверяем, что возраст введен корректно
            except Exception:
                 bot.send_message(message.from_user.id, 'Цифрами, пожалуйста');
            keyboard = types.InlineKeyboardMarkup();
            key_yes = types.InlineKeyboardButton(text='Да', callback_data='yes');
            keyboard.add(key_yes);
            key_no= types.InlineKeyboardButton(text='Нет', callback_data='no');
            question = 'Тебе '+str(age)+' лет, тебя зовут '+name+' '+surname+'?';
            bot.send_message(message.from_user.id, text=question, reply_markup=keyboard)
    
        @bot.callback_query_handler(func=lambda call: True)
    
    def callback_worker(call):
        if call.data == "yes":
            bot.send_message(call.message.chat.id, 'Запомню : )');
        elif call.data == "no":
  5. Выдает ошибку
    Python:
     File "C:\Users\Ryzen\OneDrive\Рабочий стол\Telegram\bot.py", line 69
        def callback_worker(call):
    IndentationError: unexpected unindent

Все опробывал,не вижу,Бога ради,помогите!
 
Последнее редактирование:

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Все опробывал,не вижу
Замените эти строки кода:
Python:
    @bot.callback_query_handler(func=lambda call: True)

def callback_worker(call):
    if call.data == "yes":
        bot.send_message(call.message.chat.id, 'Запомню : )');
    elif call.data == "no":
на такие
Python:
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
    if call.data == "yes":
        bot.send_message(call.message.chat.id, 'Запомню : )');
    elif call.data == "no":
 
Последнее редактирование:

Pomogite_pg_croki_goryat

Новичок
Пользователь
Дек 23, 2021
4
0
1
@bot.callback_query_handler(func=lambda call: True) def callback_worker(call): if call.data == "yes": bot.send_message(call.message.chat.id, 'Запомню : )'); elif call.data == "no":

Python:
File "C:\Users\Ryzen\OneDrive\Рабочий стол\Telegram\bot.py", line 68
    def callback_worker(call):
IndentationError: unexpected unindent
Не пойму,что такое,отступов нету вроде же...

stud_55

 
Последнее редактирование:

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Не пойму,что такое,отступов нету вроде же...
У вас в коде декоратор
Python:
@bot.callback_query_handler(func=lambda call: True)
находится внутри функции get_age и ничего не декорирует.
А должен находится вне функции и декорировать функцию callback_worker:
Python:
def get_age(message):
    global age;
    while age == 0: #проверяем что возраст изменился
        try:
             age = int(message.text) #проверяем, что возраст введен корректно
        except Exception:
             bot.send_message(message.from_user.id, 'Цифрами, пожалуйста');
        keyboard = types.InlineKeyboardMarkup();
        key_yes = types.InlineKeyboardButton(text='Да', callback_data='yes');
        keyboard.add(key_yes);
        key_no= types.InlineKeyboardButton(text='Нет', callback_data='no');
        question = 'Тебе '+str(age)+' лет, тебя зовут '+name+' '+surname+'?';
        bot.send_message(message.from_user.id, text=question, reply_markup=keyboard)


@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
    if call.data == "yes":
        bot.send_message(call.message.chat.id, 'Запомню : )');
    elif call.data == "no":
 

Pomogite_pg_croki_goryat

Новичок
Пользователь
Дек 23, 2021
4
0
1
Python:
  File "C:\Users\Ryzen\OneDrive\Рабочий стол\Telegram\bot.py", line 72
    elif call.data == "no":
IndentationError: expected an indented block after 'elif' statement on line 72

Теперь вот эта ошибка,что же такое,опять отступы!
 

stud_55

Модератор
Команда форума
Модератор
Апр 3, 2020
1 522
672
113
Теперь вот эта ошибка,что же такое,опять отступы!
У вас в коде после elif ничего нет. Нужно что-то написать, хотя бы pass.
Python:
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
    if call.data == "yes":
        bot.send_message(call.message.chat.id, 'Запомню : )');
    elif call.data == "no":
        pass
 

Форум IT Специалистов