Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
Asked Answered
G

6

9

Does anyone get errors like this? How can I fix them?

2021-11-07 08:29:38,643 - telegram.ext.updater - ERROR - Error while getting Updates: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2021-11-07 08:29:38,644 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
    Traceback (most recent call last):
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/updater.py", line 646, in _network_loop_retry
        if not action_cb():
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/updater.py", line 597, in polling_action_cb
        updates = self.bot.get_updates(
      File "/usr/local/lib/python3.8/dist-packages/telegram/ext/extbot.py", line 222, in get_updates
        updates = super().get_updates(
      File "/usr/local/lib/python3.8/dist-packages/telegram/bot.py", line 130, in decorator
        result = func(*args, **kwargs)
      File "/usr/local/lib/python3.8/dist-packages/telegram/bot.py", line 2861, in get_updates
        self._post(
      File "/usr/local/lib/python3.8/dist-packages/telegram/bot.py", line 295, in _post
        return self.request.post(
      File "/usr/local/lib/python3.8/dist-packages/telegram/utils/request.py", line 356, in post
        result = self._request_wrapper(
      File "/usr/local/lib/python3.8/dist-packages/telegram/utils/request.py", line 283, in _request_wrapper
        raise Conflict(message)
    telegram.error.Conflict: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

I get these answers from API

api.telegram.org/bot<token>/getWebhookInfo --> {"ok":true,"result":"url":"","has_custom_certificate":false,"pending_update_count":0}}
api.telegram.org/bot<token>/getUpdates --> {"ok":false,"error_code":409,"description":"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}
Gage answered 7/11, 2021 at 8:42 Comment(0)
G
7

This happens when 2 different clients send getUpdates method to Telegram servers for one bot token.

You should make sure you're not running your script more than once at the same time, or your bot token is not used somewhere else.

If you're certain that your script is executing alone and there are no other instances, then revoke your bot token from https://t.me/botfather and get a new token.

Genesisgenet answered 7/11, 2021 at 11:38 Comment(0)
P
2

Stop the bot, close your IDE, make sure that all python processes were ended in the task manager, and try again. That has helped me.

Palazzo answered 1/6, 2022 at 4:26 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Weigh
P
1

killall Python fixed my issue. (In case if you accidentally have more than 1 instance running)

Palpable answered 7/4, 2023 at 19:17 Comment(0)
H
1

When employing replication systems such as Kubernetes or Heroku Dynos, multiple instances of an application may share a single token. This can lead to errors as observed in cases where several dynos are deployed.

I experienced this issue with my Telegram application on Heroku, which was running on three dynos. Reducing the number of dynos on Heroku to 1 resolved the problem.

Harbin answered 24/4 at 18:55 Comment(0)
R
0

I fix this issue arranging code like this :

from telegram.ext import CommandHandler, Updater
from logging import basicConfig, getLogger, INFO

basicConfig(level=INFO)
log = getLogger()

def start(update, context):
    update.message.reply_text(
        "start this bot",
        parse_mode="markdown")

def help(update, context):
    update.message.reply_text(
        "help for this bot",
        parse_mode="markdown")

def main():
    updater = Updater(token=BOT_TOKEN, use_context=True)
    dispatcher = updater.dispatcher

    start_handler = CommandHandler("start", start)
    help_handler = CommandHandler("help", help)

    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    updater.start_polling()

if __name__ == '__main__':
    main()

If you are using flask, do not set debug mode to true also on your development server, first call main function then call flask server like this:-

app = Flask(__name__)

if __name__ == '__main__':
    main()
    app.run()
Roundlet answered 1/3, 2022 at 12:7 Comment(0)
P
0

In my case, there is more than 1 instance running
Check how many instances are running with this cmd: ps aux | grep python

You will receive information as below

root     3619376  0.0  0.1 140528  6992 ?        S    04:41   0:00 sudo -u www /www/python/Bot//927389dde9b_venv/bin/python3 -u /www/python/Bot/bot.py
root     3619379  0.0  0.1 140528  7212 ?        S    04:41   0:00 sudo -u www /www/python/Bot//927389dde9b_venv/bin/python3 -u /www/python/Bot/bot.py

If there are more than 1 instance then you need to kill those instances
sudo kill 3619376 3619379

3619376, 3619379 is the process id
Then you can restart the bot

Note that only kill if the process id has the same path

Plutonic answered 25/8 at 22:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.