herokutelegram-botpython-telegram-bot

Telegram bot python error in webhooks heroku


I deploy a bot in heroku but it give a erro

   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

Well, i tryed all port 80, 88, 8443 but it give me the same erro again.

My hook and port code:

#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: In localhost work very well


Solution

  • Given the date of this question, I assume that you're using PTB v13.4+. In that case, please see this channel post, i.e. change

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

    to

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