|
37 | 37 | from __future__ import print_function
|
38 | 38 |
|
39 | 39 | import os
|
40 |
| -from requests_kerberos.exceptions import KerberosExchangeError |
41 | 40 | from typing import Any, Dict, List, Optional, Text, Tuple, Union # NOQA for mypy types
|
42 | 41 |
|
43 | 42 | import requests
|
@@ -240,6 +239,16 @@ def __init__(
|
240 | 239 | raise ValueError('cannot use authentication with HTTP')
|
241 | 240 | self._auth.set_http_session(self._http_session)
|
242 | 241 |
|
| 242 | + default_exceptions = ( |
| 243 | + PrestoRequest.http.ConnectionError, # type: ignore |
| 244 | + PrestoRequest.http.Timeout, # type: ignore |
| 245 | + ) |
| 246 | + try: |
| 247 | + from requests_kerberos.exceptions import KerberosExchangeError |
| 248 | + self._exceptions = default_exceptions + (KerberosExchangeError,) |
| 249 | + except ImportError: |
| 250 | + self._exceptions = default_exceptions |
| 251 | + |
243 | 252 | self._redirect_handler = redirect_handler
|
244 | 253 | self._request_timeout = request_timeout
|
245 | 254 | self._handle_retry = handle_retry
|
@@ -298,11 +307,7 @@ def max_attempts(self, value):
|
298 | 307 |
|
299 | 308 | with_retry = exceptions.retry_with(
|
300 | 309 | self._handle_retry,
|
301 |
| - exceptions=( |
302 |
| - KerberosExchangeError, |
303 |
| - PrestoRequest.http.ConnectionError, # type: ignore |
304 |
| - PrestoRequest.http.Timeout, # type: ignore |
305 |
| - ), |
| 310 | + exceptions=self._exceptions, |
306 | 311 | conditions=(
|
307 | 312 | # need retry when there is no exception but the status code is 503
|
308 | 313 | lambda response: getattr(response, 'status_code', None) == 503,
|
|
0 commit comments