From b758cde4789f7b4de9008e1f73ac6f1b30c73610 Mon Sep 17 00:00:00 2001 From: Csaba Ringhofer Date: Mon, 15 Apr 2024 19:06:15 +0200 Subject: [PATCH] Add winkerberos as an alternative dependency for kerberos Based on another PR: https://github.com/cloudera/impyla/pull/504 --- README.md | 1 + impala/_thrift_api.py | 9 ++++++++- setup.py | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a028c9cd..fef875612 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Optional: * `kerberos>=1.3.0` for Kerberos over HTTP support. This also requires Kerberos libraries to be installed on your system - see [System Kerberos](#system-kerberos) + * On Windows operating systems an alternative is 'winkerberos' which can be installed with pip * `pandas` for conversion to `DataFrame` objects; but see the [Ibis project][ibis] instead diff --git a/impala/_thrift_api.py b/impala/_thrift_api.py index 6b97bb8c1..bd9c96e03 100644 --- a/impala/_thrift_api.py +++ b/impala/_thrift_api.py @@ -442,7 +442,14 @@ def get_custom_headers(cookie_header, has_auth_cookie): elif auth_mechanism == 'GSSAPI': # For GSSAPI over http we need to dynamically generate custom request headers. def get_custom_headers(cookie_header, has_auth_cookie): - import kerberos + # Try importing kerberos, then winkerberos as fallback. Report the original exception for kerberos. + try: + import kerberos + except ImportError as original_ex: + try: + import winkerberos as kerberos + except ImportError: + raise original_ex custom_headers = {} if cookie_header: log.debug('add cookies to HTTP header') diff --git a/setup.py b/setup.py index 932315d56..782c154fe 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ def readme(): install_requires=['six', 'bitarray', 'thrift==0.16.0', 'thrift_sasl==0.4.3'], extras_require={ "kerberos": ['kerberos>=1.3.0'], + "winkerberos": ['winkerberos'], }, keywords=('cloudera impala python hadoop sql hdfs mpp spark pydata ' 'pandas distributed db api pep 249 hive hiveserver2 hs2'),