python操作有Kerberos认证的hive库

之前访问hive都比较简单,直接用pyhive连接即可。
但是最近遇到了一个问题,hive有了Kerberosren认证。
最终经过各种尝试和灵感迸发,终于解决了这个问题,遂记录之。

  • 代码
from pyhive.hive import connect
con = connect(host='XXXX',port=10000,auth='KERBEROS',kerberos_service_name="hive")
cursor = con.cursor()
cursor.execute('select * from tmp.pricing_calculate_result_spark  where time_id="201907171355" limit 10,1')
datas = cursor.fetchall()
print(datas)
cursor.close()
con.close()

端口和ip都换成自己的,auth和kerberos_service_name不要改

  • 运行效果
    在这里插入图片描述

你可能感兴趣的:(hive)