python 在渲染器上部署电报机器人时出错

aydmsdu9  于 2023-05-16  发布在  Python
关注(0)|答案(1)|浏览(140)

我试图在Render上部署这个电报机器人,但部署总是失败(尽管在我收到构建成功日志后的第一分钟,它工作得很好)。然而,几分钟后,部署失败,我一直得到这个错误日志:

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

下面是我编写的“bot.py“脚本。取消了代码中一些不重要的部分。此外,所有的“src.”模块都是我创建的,以更好地组织代码。这些模块上没有使用远程机器人方法。

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()

已经在telegram上撤销了一个旧的API_key,并使用了一个新生成的,没有任何变化。
编辑:在本地运行时工作完美。只收到此警告:

\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.
eqqqjvef

eqqqjvef1#

我通过使用“clear build cache and deploy”选项而不是“deploy latest commit”解决了这个问题。并在启动bot时执行错误处理。我使用grammy创建了这个bot。
然而,在我得出这个结论之前,我认为有一件事可以解决我的问题,那就是实现一个webhook解决方案,而不是使用长轮询。但我不知道这是否真的能解决问题。

相关问题