【问题标题】:Telegram bot python erro in webhooks herokuwebhooks heroku中的Telegram bot python错误
【发布时间】:2021-04-03 03:10:14
【问题描述】:

我在 heroku 中部署了一个机器人,但它给出了一个错误

   2021-04-03T02:56:36.610385+00:00 app[web.1]: 2021-04-03 02:56:36,604 - apscheduler.scheduler - INFO - Scheduler started
    2021-04-03T02:56:37.316107+00:00 app[web.1]: 2021-04-03 02:56:37,315 - telegram.ext.updater - ERROR - Error while bootstrap set webhook: Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443
    2021-04-03T02:56:37.316196+00:00 app[web.1]: 2021-04-03 02:56:37,316 - telegram.ext.updater - ERROR - Failed bootstrap phase after 0 retries (Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443)
2021-04-03T02:47:04.325287+00:00 app[web.1]: 2021-04-03 02:47:04,317 - telegram.ext.updater - ERROR - unhandled exception in Bot:1718309867:updater

好吧,我尝试了所有端口 80、88、8443,但它又给了我同样的错误。

我的钩子和端口代码:

#change PORT TO HEROKU
PORT = int(os.environ.get('PORT', '8443'))

updater = Updater(SECRET_KEY, use_context=True)

 #hook to heroku
updater.start_webhook(listen="0.0.0.0",
                          port=PORT,
                          url_path=SECRET_KEY)
    updater.bot.set_webhook('https://myapp.herokuapp.com/' + SECRET_KEY)

PS:在 localhost 中工作得很好

【问题讨论】:

    标签: heroku telegram-bot python-telegram-bot


    【解决方案1】:

    鉴于此问题的日期,我假设您使用的是 PTB v13.4+。这种情况请看this channel post,即改

    updater.start_webhook(listen="0.0.0.0",
                              port=PORT,
                              url_path=SECRET_KEY)
        updater.bot.set_webhook('https://myapp.herokuapp.com/' + SECRET_KEY)
    

    updater.start_webhook(listen="0.0.0.0",
                          port=PORT,
                          url_path=SECRET_KEY,
                          webhook_url='https://myapp.herokuapp.com/' + SECRET_KEY)
    

    【讨论】:

    • 没错。我在requirement.txt中做了一个downgree才能工作。现在有了这个结构,我可以回到最新版本。效果很好 非常感谢
    猜你喜欢
    • 2018-04-24
    • 2021-06-21
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2021-08-29
    • 2022-11-11
    相关资源
    最近更新 更多