Skip to main content
andrea_pretotto
Silver ⭐️⭐️⭐️
Sep 29, 2023 2:14 PM UTC
Question

Error connecting to Kerberos using pyHive library

Hi,
in a Unix environment, I get this error while connecting to Hive via Kerberos, using the library pyHive in a python script:

thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-1) SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure. Minor code may provide more information (Server krbtgt/LOCAL.IT@EXAMPLE.IT not found in Kerberos database)'

I am able to connect to Kerberos using "kinit -kt user user.keytab", and also via Hive ODBC driver. I use the same krb5.conf file, with Default Realm = EXAMPLE.IT.

With kinit, I obtain, correctly:

Default principal: user@EXAMPLE.IT
Valid starting Expires Service principal
09/28/23 11:05:16 09/28/23 11:05:16 krbtgt/EXAMPLE.IT@EXAMPLE.IT

The error is only using pyHive library. In the error, the library uses the domain LOCAL.IT instead of the one specified in krb5.conf, that is EXAMPLE.IT

My connection in pyHive:

conn = hive.Connection(host="host.domain.it",
port=10000,
auth="KERBEROS",
database="db_123",
kerberos_service_name="hive")

Note that LOCAL.IT is equal to domain.it.

Can you help me?

Thank you

4 replies

cravani
Gold ⭐️
Gold ⭐️
Sep 29, 2023 5:27 PM UTC

PyHive is not maintained by Cloudera, Can you use Impyla to connect to HiveServer2? It should work with HS2 also.

Ref: https://github.com/cloudera/impyla

Translate
mszurap
Platinum ⭐️
Platinum ⭐️
Oct 2, 2023 8:56 AM UTC

Hi @andrea_pretotto 

Additionally, you can also choose to use PyODBC:

https://pypi.org/project/pyodbc/

together with the Cloudera Hive ODBC drivers:

https://cloudera.com/downloads/connectors/hive/odbc 

This should give the best compatibility with Hive.

Best regards

 Miklos

Translate
andrea_pretotto
Silver ⭐️⭐️⭐️
Oct 2, 2023 4:23 PM UTC

Hi,

thank you for the answers.

@cravani unfortunately Impala is not used. About pyODBC, @mszurap , it sounds like the best option to adopt. We will work with this, and we will update you soon.

Best regards

Andrea

 

Translate
DianaTorres
Community Manager
Community Manager
Oct 6, 2023 11:40 PM UTC

@andrea_pretotto Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. Thanks.

Translate
Regards, Diana Torres, Senior Community Moderator