Have problem while deploying telegram bot on cpanel

288 views Asked by At

I have deployed a telegram bot made with flask and pyTelegramBotAPI. But I have issues with setting webhook.

If I set WEBHOOK_PORT = 88. I got this error:

returncode: 1
stdout:
* Serving Flask app 'main'
 * Debug mode: on
stderr:
Permission denied

And if some ports except 443, 80, 88 or 8443

telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 or 8443

I got this. Can anyone help?

1

There are 1 answers

2
Iman Mohammadi On

I've found 2 issues:

  1. Permission Denied Issue: This is typically due to trying to bind to a port below 1024 on Unix-like systems without superuser privileges. Ports below 1024 are considered "privileged" ports, and only the root user (or a process with the appropriate capabilities) can bind to them.

  2. Webhook Port Issue: Telegram allows setting webhooks only on the specified ports: 80, 88, 443, or 8443. If you try any other port, you'll get the error you mentioned.

So in order to solve them,

1. For Permission Denied Issue

To run your Flask app on a port like 88, you need to use sudo to grant it the required permissions:

sudo python3 your_flask_app.py

2. For the Webhook Port Issue

Ensure you're using one of the ports allowed by Telegram: 80, 88, 443, or 8443. You mentioned trying port 88, so once you resolve the permission issue, setting the webhook on this port should work.

However, if you opt for ports 80 or 443, remember they're commonly used for HTTP and HTTPS, respectively. If you have other services using these ports (like a web server), you'll need to configure them to either use a different port or proxy requests to your Flask application.