S
S
Studentka19962021-06-29 20:33:07
Bots
Studentka1996, 2021-06-29 20:33:07

How to fix 409 Conflict error in Telegram bot?

Why can't I use the bot variable in another file? Error, supposedly the bot is already running (one instance of the bot is running). Please help.

main.py

@bot.callback_query_handler(func=lambda msg: True) 
def callback_Func(callback_query):
    message = callback_query.message
    text = callback_query.data

    user.send_mess(f'Оплатите заказ в течении 30 минут, иначе заказ аннулируется', 
             buttons.ls_keybs_orders(message.chat.id)[0], message.chat.id, message.message_id)


user.py

def send_mess(mess, st_order, chat_id, mess_id, bot):
    print(st_order)
    bot.edit_message_text(chat_id = chat_id, message_id = mess_id, text = f'*Ваш заказ № {conn_DB.id_Zakaz()}'\
          f' СФОРМИРОВАН!* {mess}.\n Спасибо за заказ, *ожидайте звонка* \U0001f4de.',
             parse_mode = "Markdown", reply_markup = buttons.send_keyb_order(st_order))


Error text:
telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 409 Conflict. Response body:
[b'{"ok":false,"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}']

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Studentka1996, 2021-06-30
@Studentka1996

Starting the bot with __main__ helped

if __name__ == '__main__': # чтобы код выполнялся только при запуске в виде сценария, а не при импорте модуля
    try:
       bot.polling(none_stop=True) # запуск бота
    except Exception as e:
       print(e) # или import traceback; traceback.print_exc() для печати полной инфы
       time.sleep(15)

J
John Jameson, 2021-06-29
@JohnJameson

Try to create a new bot and connect the token to it

V
Vasily Bannikov, 2021-06-29
@vabka

Perhaps you have a webhook set up and you are trying to do getUpdates
https://stackoverflow.com/questions/36120529/teleg...
Or getUpdates comes from multiple threads/processes
Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question