CentOS环境下Python连接impala问题解决过程

环境

 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吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值