How to handle the error of enabling telegram bot?

I have a telegram bot, but over time or immediately upon startup it gets a connection error. To write a bot, I use the "telebot" library.

requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bottoken/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02FB6910>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))

How to handle this error and try to turn on the bot until it turns on?

Upvotes: 1

Views: 2032

Answers (1)

VnC
VnC

Reputation: 2026

Try the following - use ConnectionError from requests.eceptions

from requests.exceptions import ConnectionError

try:
   Bot working and doing stuff
except ConnectionError as e:
   log e
   start Bot()

Upvotes: 1

Related Questions