Skip to content

Commit dfe0240

Browse files
takutiggreg
authored andcommitted
Make the library runnable w/ and w/o requests_kerberos
1 parent 25cf54c commit dfe0240

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

prestodb/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from __future__ import division
1414
from __future__ import print_function
1515

16+
try:
17+
from .auth import KerberosAuthentication
18+
except ImportError:
19+
pass
20+
1621
from . import dbapi
1722
from . import client
1823
from . import constants

prestodb/client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from __future__ import print_function
3838

3939
import os
40-
from requests_kerberos.exceptions import KerberosExchangeError
4140
from typing import Any, Dict, List, Optional, Text, Tuple, Union # NOQA for mypy types
4241

4342
import requests
@@ -240,6 +239,16 @@ def __init__(
240239
raise ValueError('cannot use authentication with HTTP')
241240
self._auth.set_http_session(self._http_session)
242241

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+
243252
self._redirect_handler = redirect_handler
244253
self._request_timeout = request_timeout
245254
self._handle_retry = handle_retry
@@ -298,11 +307,7 @@ def max_attempts(self, value):
298307

299308
with_retry = exceptions.retry_with(
300309
self._handle_retry,
301-
exceptions=(
302-
KerberosExchangeError,
303-
PrestoRequest.http.ConnectionError, # type: ignore
304-
PrestoRequest.http.Timeout, # type: ignore
305-
),
310+
exceptions=self._exceptions,
306311
conditions=(
307312
# need retry when there is no exception but the status code is 503
308313
lambda response: getattr(response, 'status_code', None) == 503,

0 commit comments

Comments
 (0)