Python connect to Hive use pyhs2 and Kerberos auth

2019-05-18 03:24发布

问题:

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/app-20.photo.163.org@HADOOP.HZ.NETEASE.COM?mapred.job.queue.name=default

回答1:

I think it will be something like this:

pyhs2.connect(host='biclient2.server.163.org',
                   port=10000,
                   authMechanism="KERBEROS",
                   password="something",
                   user='your_user@HADOOP.HZ.NETEASE.COM')

I'm also doing the same, I still not succeed, but at least having a meaningful errorcode: (Server hive/xxx@yyy.COM not found in Kerberos database)



回答2:

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.



标签: python jdbc hive