我有一个要连接电报机器人的代理地址列表。 代理可能会随着时间的流逝而阻塞,或者根本无法正常工作,这可以通过MaxRetryError错误看到。 但是我找不到错误。我在日志中有一个错误。 我想捕获一个错误并切换到另一个代理服务器。
from telegram.ext import Updater
REQUEST_KWARGS = {
'proxy_url': proxy_url,
'urllib3_proxy_kwargs': {
'retries': 0
}
}
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
.....
raise MaxRetryError(_pool, url, error or ResponseError(cause))
telegram.vendor.ptb_urllib3.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
......
telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
2019-07-26 16:07:38,553 - telegram.ext.dispatcher - CRITICAL - stopping due to exception in another thread
答案 0 :(得分:0)
这个way吗?
try:
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
except MaxRetryError:
#doSomething