Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python connect to Hive use pyhs2 and Kerberos authentication

Tags:

python

jdbc

hive

I'm connecting Hive use pyhs2. But the Hive server required Kerberos authentication. Anyone knows how to convert the JDBC string to pyhs2 parameter? Like: jdbc:hive2://biclient2.server.163.org:10000/default;principal=hive/[email protected]?mapred.job.queue.name=default

like image 564
leeyiw Avatar asked Jan 08 '23 12:01

leeyiw


2 Answers

I think it will be something like this:

pyhs2.connect(host='biclient2.server.163.org',
                   port=10000,
                   authMechanism="KERBEROS",
                   password="something",
                   user='[email protected]')

I'm also doing the same, I still not succeed, but at least having a meaningful errorcode: (Server hive/[email protected] not found in Kerberos database)

like image 122
kecso Avatar answered Jan 11 '23 03:01

kecso


This connection string will work as long as the user running the script has a valid kerberos ticket:

import pyhs2

with pyhs2.connect(host='biclient2.server.163.org',
                    port=10000,
                    authMechanism="KERBEROS") as conn:

    with conn.cursor() as cur:
            print cur.getDatabases()

Username, password and any other configuration parameters are not passed through the KDC.

like image 34
pele88 Avatar answered Jan 11 '23 03:01

pele88