繁体   English   中英

如何捕获异常MaxRetryError?

[英]How to catch exception MaxRetryError?

我有一个要连接电报机器人的代理地址列表。 代理可能会随着时间的流逝而阻塞,或者根本无法正常工作,这可以通过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

这样

try:
  updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
  queue = updater.start_polling(bootstrap_retries=0)
except MaxRetryError:
  #doSomething

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM