如何处理启用电报机器人的错误?

时间:2019-04-23 14:27:46

标签: python python-3.x telegram

我有一个电报漫游器,但是随着时间的流逝或启动后立即出现连接错误。要编写机器人,我使用“ telebot”库。

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)'))

如何处理此错误并尝试打开机器人,直到它打开?

1 个答案:

答案 0 :(得分:1)

尝试以下操作-使用ConnectionError中的requests.eceptions

from requests.exceptions import ConnectionError

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