<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Python connect to Hadoop using Hive with Kerberos authentication in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Python-connect-to-Hadoop-using-Hive-with-Kerberos/m-p/167067#M129399</link>
    <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/14201/siddharthpeesary.html" rel="nofollow noopener noreferrer" target="_blank"&gt;@siddharth peesary&lt;/A&gt;&lt;/P&gt;&lt;P&gt;1. You must install kerberos client on your PC.&lt;/P&gt;&lt;P&gt;2. You mast get and kinit a ticket for kerberos.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11205-krb5.png" style="width: 740px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/20309i7A04F57EE585C181/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11205-krb5.png" alt="11205-krb5.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;3. And then you must install Pyhive model.&lt;/P&gt;&lt;P&gt;4. Then test.py like this:&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/env python
# -*- coding: utf-8 -*-
# hive util with hive server2
from impala.dbapi import connect


class HiveClient:
    def __init__(self, db_host, port, authMechanism, user, password, database, kbservice):
        self.conn = connect(host=db_host,
                            port=port,
                            auth_mechanism=authMechanism,
                            user=user,
                            password=password,
                            database=database,
                            kerberos_service_name=kbservice
                            )


    def query(self, sql):
        with self.conn.cursor() as cursor:
            cursor.execute(sql)
            return cursor.fetchall()


    def close(self):
        self.conn.close()


if __name__ == '__main__':
    hive_client = HiveClient(db_host='namenode02.xxx.com', port=10000, authMechanism='GSSAPI', user='hive', password='',
                             database='data_mp_raw', kbservice='hive')
    sql = "select dt, hour, vid, sum(1) as play_num from tbl_mp_stream where dt='20161204' and hour='12' and vid is not null group by dt, hour, vid order by play_num desc limit 50"
    sql = "SHOW TABLES"
    result = hive_client.query(sql)
    hive_client.close()
    for x in result:
        print(x)
&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/14201/siddharthpeesary.html" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;/A&gt;5. The result like this( My python version is 3.5.2 )&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="11206-test-hive.png" style="width: 507px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/20310i782CB2E19793D382/image-size/medium?v=v2&amp;amp;px=400" role="button" title="11206-test-hive.png" alt="11206-test-hive.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2019 11:10:16 GMT</pubDate>
    <dc:creator>monkeyluo1202</dc:creator>
    <dc:date>2019-08-18T11:10:16Z</dc:date>
  </channel>
</rss>

