【发布时间】:2021-09-08 19:01:10
【问题描述】:
大多数指南和帖子都在讨论相反的情况,即您决定提前重试哪些异常。也许我想错了,但是例如,我正在尝试获取 google 服务帐户凭据
def get_google_credentials(self, google_creds_dict):
SCOPES = [
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/spreadsheets',
]
credentials = service_account.Credentials.from_service_account_info(google_creds_dict, scopes=SCOPES)
return credentials
由于我知道它返回 ValueError,我想我只想重试其他异常
【问题讨论】:
-
只需添加多个例外 -
try: do stuff; except ValueError: pass; except IndexError: do stuff
标签: python retry-logic