依赖包
# 依赖包异常地址
# https://www.lfd.uci.edu/~gohlke/pythonlibs/
pip install bitarray==0.9.3
pip install pure-sasl==0.6.1
pip install thrift_sasl==0.2.1 --no-deps
pip install thrift==0.11.0
pip install thriftpy==0.3.9
pip install impyla==0.16.0
连接代码
from impala.dbapi import connect
# hive, 无密码, 无kerberos
conn = connect(host='172.16.163.5', port=10000, auth_mechanism='PLAIN')
# impala, 无密码, 无kerberos
conn = connect(host='172.16.163.5', port=21050)
# impala, 有密码, 有kerberos
conn = connect(host='172.16.163.216', port=21050, auth_mechanism='PLAIN', user='hive', password='password')
# hive, 有密码, 有kerberos
conn = connect(host='172.16.163.216', port=10000, auth_mechanism='PLAIN', user='hive', password='password')
cursor = conn.cursor()
cursor.execute('show databases')
results = cursor.fetchall()
print(results)
异常解决
错误:
thriftpy.transport.TTransportException: 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和pure-sasl有冲突,这种情况下,直接卸载sasl包就行了。
pip uninstall SASL
错误:
TypeError: can't concat str to bytes
解决办法:
/python36/Lib/site-packages/thrift_sasl-0.2.1-py3.6.egg(windows下好压打开)/thrift_sasl/__init__.py
或
/python36/Lib/site-packages/thrift_sasl/__init__.py
92行 修改为:
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()
网友评论