1414
1515import requests
1616
17- from google .api_core import exceptions
17+ from google .api_core import exceptions as api_exceptions
1818from google .api_core import retry
19+ from google .auth import exceptions as auth_exceptions
1920
2021import json
2122
2223
2324_RETRYABLE_TYPES = (
24- exceptions .TooManyRequests , # 429
25- exceptions .InternalServerError , # 500
26- exceptions .BadGateway , # 502
27- exceptions .ServiceUnavailable , # 503
28- exceptions .GatewayTimeout , # 504
25+ api_exceptions .TooManyRequests , # 429
26+ api_exceptions .InternalServerError , # 500
27+ api_exceptions .BadGateway , # 502
28+ api_exceptions .ServiceUnavailable , # 503
29+ api_exceptions .GatewayTimeout , # 504
2930 requests .ConnectionError ,
3031)
3132
@@ -37,8 +38,10 @@ def _should_retry(exc):
3738 """Predicate for determining when to retry."""
3839 if isinstance (exc , _RETRYABLE_TYPES ):
3940 return True
40- elif isinstance (exc , exceptions .GoogleAPICallError ):
41+ elif isinstance (exc , api_exceptions .GoogleAPICallError ):
4142 return exc .code in _ADDITIONAL_RETRYABLE_STATUS_CODES
43+ elif isinstance (exc , auth_exceptions .TransportError ):
44+ return _should_retry (exc .args [0 ])
4245 else :
4346 return False
4447
0 commit comments