簡體   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