Python telegram bot deploy failure

I am trying to deploy this telegram bot, but the deploy always fails (although on the first minutes after I receive the build successful log, it works perfectly). However, minutes later the deploy fails and I keep getting this error log:

telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. 
Error code: 409. Description: Conflict: terminated by other getUpdates request; 
make sure that only one bot instance is running

Here is the “bot.py” script I coded. Suppressed some non important parts of the code. Also, all “src.” modules were created by me for better code organization. There are no telebot methods called by those modules.
#generic code supressed below, means no telebot method is being called. One can think as a simple print(“Hello World”) instead.

import pandas as pd
from datetime import datetime, date
import src.visualization.visualize as vz
import src.auxiliary.auxiliary as aux
import src.data.wrangling as w
import src.data.database as db
import os

import telebot

API = os.getenv("API_KEY")
bot = telebot.TeleBot(API)

@bot.message_handler(commands=["IBOVESPA", "SP500", "NASDAQ"])
def responder(mensagem):
    # generic code and calculations suppressed
    if condition:
    # telebot method used
        bot.send_photo(
            mensagem.chat.id,
            photo = photo
        )
        
    else:
        # more generic code suppressed
    # telebot method used
        bot.send_message(
            mensagem.chat.id,
            aux.create_answer(assets)
        )
        # telebot method used
        bot.send_photo(
            mensagem.chat.id,
            photo = photo
        )

def verificar(mensagem):
    return True

def calculating_msg(mensagem, date):
    # telebot method used
    bot.send_message(
        mensagem.chat.id, 
        “generic answer”
    )

@bot.message_handler(func=verificar)
def responder(mensagem):
    text= ( 
            “standard reply to any message”
        )
    # telebot method used
    bot.reply_to(mensagem, text)

# telebot method used
bot.polling()

Already revoked an old api_key on telegram and used a fresh-generated one and nothing changes.

Also, it works perfectly running on local. Only receive this warning:

\src\visualization\visualize.py:34: UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail.
  fig = plt.figure(figsize=(15, 8))
WARNING: QApplication was not created in the main() thread.

Hey there,

It looks like you might be attempting to run a bot on Render, there are a bunch of things that you probably need to know.

Bots are best deployed to us using a Background Worker - these run persistently in the background and don’t expose any web server however, these service types aren’t available with a free instance type.

If you try and run a bot via a Web Service, the deployment will probably fail, typically about 10 minutes after you’ve deployed it, and sometimes there are scenarios where 2 may be running for a period of time, this is down to our zero-downtime feature and not something that can be disabled.

We’ve been alerted to issues running Discord bots on us being rate limited by Discord, this is down to how traffic leaves our services - this may result in you receiving a 429 from Discord or having your requests rate limited - we’ve reached out to Discord but we don’t have a solution here yet.

If this doesn’t answer your question, just let us know, and we’ll try and help where we can

Regards,

John B

Ok @John_B, thank you for your explanation.

Hi I’m getting the same issue, are there some news about solving this error?

No, you might try deploying as a Flask app. It should work.

No, you might try deploying as a Flask app. It should work.

Is there any documentation?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.