按顺序安装如下模块
pip install pure-sasl==0.5.1
pip install thrift_sasl==0.2.1
pip install thrift==0.9.3
pip install impyla
测试代码:
from impala.dbapiimportconnect
conn = connect(host='127.0.0.1', port=10000, database='default',auth_mechanism='PLAIN')
cur = conn.cursor()
cur.execute('SHOW DATABASES')
print(cur.fetchall())
不出所料会报错:
TypeError: can't concat str to bytes
定位到对应代码,如下:
def _send_message(self,status,body):
header= struct.pack(">BI",status,len(body))
self._trans.write(header+ body)
self._trans.flush()
修改为如下:
def _send_message(self,status,body):
header= struct.pack(">BI",status,len(body))
if(type(body)is str):
body= body.encode()
self._trans.write(header+ body)
self._trans.flush()
如果还有报如下错误:
TTransportException(type=1, message="Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'")
检查是否安装了sasl,sasl模块会和pure-sasl模块冲突。如果有,卸载sasl。
pip show sasl
pip uninstall sasl
如果还是报错,请卸载全部相关包重新安装,版本号一定要对。
网友评论