环境
CentOS7 & Python 3.6.6
安装impyla及其相关依赖,注意版本号
版本号不对,可能会造成错误
pip install -r requirement.txt
requirement.txt
impyla==0.14.1
bitarray==0.8.1
six==1.11.0
thrift==0.11.0
thrift-sasl==0.2.1
thriftpy==0.3.9
安装完成后测试
from impala.dbapi import connect
conn = connect(host='IP地址', auth_mechanism="PLAIN", port=21050, user="XXX", password="XXX")
cur = conn.cursor()
res = cur.execute('select now()')
发现运行到第二行就报错了
thriftpy.transport.TTransportException: TTransportException(type=1, message="Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: No worthy mechs found'")
看报错信息,分析下来应该是和auth_mechanism机制有关,在网上搜索,在github上找到这个issue#290
自己输入一下rpm命令,输出是这样的
# rpm -qa | grep sasl
cyrus-sasl-lib-2.1.26-23.el7.x86_64
cyrus-sasl-devel-2.1.26-23.el7.x86_64
cyrus-sasl-2.1.26-23.el7.x86_64
而网友的输出有很多,对比一下,我发现了这个cyrus-sasl-plain-2.1.26-21.el7.x86_64。
这个应该是和auth_mechanism="PLAIN"是对应的。而我机器上没装
装一下就好了
# yum install cyrus-sasl-plain -y
# rpm -qa | grep sasl
cyrus-sasl-plain-2.1.26-23.el7.x86_64
cyrus-sasl-lib-2.1.26-23.el7.x86_64
cyrus-sasl-devel-2.1.26-23.el7.x86_64
cyrus-sasl-2.1.26-23.el7.x86_64
之后Python就能顺利的连接impala了
注:
我也尝试过更改auth_mechanism
from impala.dbapi import connect
conn = connect(host='IP地址', auth_mechanism="NOSASL", port=21050, user="XXX", password="XXX")
cur = conn.cursor()
res = cur.execute('select now()')
第二行没有报错,但是第三行就报错了。
impala.error.HiveServer2Error: Failed after retrying 3 times
可能是我的HiveServer不接受这种auth的mechanism吧~