N
N
NaZaR_4iK2022-04-16 22:34:21
Python
NaZaR_4iK, 2022-04-16 22:34:21

How to solve IndexError: list index out of range error?

try:
        if user_channel_status[70] != 'left':
            print()
        else:
            await bot.send_message(message.chat.id, '')
    except:
        if user_channel_status[60] != 'left':
            await bot.send_message(message.from_user.id, '')
        else:
            await bot.send_message(message.from_user.id, '')
        await bot.answer_callback_query(call.id)


Please help.
In the lines
if user_channel_status[70] != 'left':
if user_channel_status[60] != 'left': An
IndexError

: list index out of range is thrown

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-04-16
@sergey-gornostaev

Obviously user_channel_status does not have elements with index 60 and 70. You can solve the problem by checking the length of the list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question