python 连接使用LDAP认证的hive

python 连接使用LDAP认证的hive

主要使用pyhive包。

使用linux中的普通账号,venv环境。python版本 3.6.4。

ldap认证需要sasl包,在安装sasl包的时候因为机器中没有g++编译器,导致无法安装。因为我使用的普通账号,没法给服务器安装g++编译器,解决的方案是在另一台机器中安装sasl,将安装完成后生成的.so动态链接库文件及py文件直接拷贝到合适目录即可使用。

以下是连接hive的示例代码:

#!/bin/python
# -*- coding: utf-8 -*-

import sys,pyhive
from pyhive import hive

cursor=hive.connect('x.x.x.x',auth='LDAP',username='testuser',password='testpass').cursor()
cursor.execute("select 1")
print(cursor.fetchall())

以上。