question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad webhook error on start up

See original GitHub issue

I just deployed this to Heroku and I think I got everything right but I’m getting an error when the app tries to start… telegram.error.BadRequest: Bad webhook

I’ve checked the URL as per the first line of output but there’s not many other clues… it’s running on a free dyno if that makes a difference?

app[web.1]: Running bot in webhook mode. Make sure that this url is correct: https://<app-name>.herokuapp.com/
app[web.1]: Error while bootstrap set webhook: Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443
app[web.1]: Failed bootstrap phase after 0 retries (Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443)
app[web.1]: unhandled exception in Bot:1782207609:updater
app[web.1]: Traceback (most recent call last):
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 236, in _thread_wrapper
app[web.1]:     target(*args, **kwargs)
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 602, in _start_webhook
app[web.1]:     ip_address=ip_address,
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 674, in _bootstrap
app[web.1]:     bootstrap_interval,
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 530, in _network_loop_retry
app[web.1]:     onerr_cb(telegram_exc)
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 652, in bootstrap_onerr_cb
app[web.1]:     raise exc
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 516, in _network_loop_retry
app[web.1]:     if not action_cb():
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/updater.py", line 640, in bootstrap_set_webhook
app[web.1]:     drop_pending_updates=drop_pending_updates,
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py", line 127, in decorator
app[web.1]:     result = func(*args, **kwargs)
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py", line 2863, in set_webhook
app[web.1]:     result = self._post('setWebhook', data, timeout=timeout, api_kwargs=api_kwargs)
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/bot.py", line 260, in _post
app[web.1]:     f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py", line 354, in post
app[web.1]:     **urlopen_kwargs,
app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/telegram/utils/request.py", line 272, in _request_wrapper
app[web.1]:     raise BadRequest(message)
app[web.1]: telegram.error.BadRequest: Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
stikhonchukcommented, Mar 28, 2021

Вот такая штука сработала (по мотивам https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku)

import os

from telegram.ext import Updater

from handlers import setup_dispatcher
from settings import TELEGRAM_TOKEN, HEROKU_APP_NAME

PORT = int(os.environ.get('PORT', '8443'))

# Setup bot handlers
updater = Updater(TELEGRAM_TOKEN)

dp = updater.dispatcher
dp = setup_dispatcher(dp)

# Run bot
if not HEROKU_APP_NAME:  # pooling mode
    print("Can't detect 'HEROKU_APP_NAME' env. Running bot in pooling mode.")
    print("Note: this is not a great way to deploy the bot in Heroku.")

    updater.start_polling()
    updater.idle()

else:  # webhook mode
    print(f"Running bot in webhook mode. Make sure that this url is correct: https://{HEROKU_APP_NAME}.herokuapp.com/")
    updater.start_webhook(
        listen="0.0.0.0",
        port=PORT,
        url_path=TELEGRAM_TOKEN,
        webhook_url=f"https://{HEROKU_APP_NAME}.herokuapp.com/{TELEGRAM_TOKEN}"
    )

#    updater.bot.set_webhook(f"https://{HEROKU_APP_NAME}.herokuapp.com/{TELEGRAM_TOKEN}")
    updater.idle()
0reactions
ohldcommented, Mar 29, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

python-telegram-bot.I already PORT 8443 but Error while ...
I already PORT 8443 but Error while bootstrap set webhook: Bad webhook: webhook can be set up only on ports 80, 88, 443...
Read more >
Common Webhook Errors | SignalWire Developer Portal
Below are some examples of common errors that you might encounter when using webhooks. If you are unable to resolve your issue, you...
Read more >
Anyone got telegram webhooks working? - Configuration
This is the error i got: telegram.error.BadRequest: 'Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 or...
Read more >
Guide for Troubleshooting GitHub Webhooks - Hookdeck
Another error that can occur with GitHub webhooks is a 400 HTTP error, which indicates a bad request. One thing to note when...
Read more >
Help with 'Bad payload received' error when trying...
I have a flow that stores some variables. I want to output those variable to a Teams group. In Teams I have set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found