python3.5连接hive(impala)

环境

python 3.5
win 7

一、按照以下顺序安装所需的包及版本:

pip install pure-sasl
pip install thrift_sasl==0.2.1 --no-deps
pip install thrift==0.9.3
pip install impyla
pip install thriftpy这里是引用

二、安装完成之后 测试连接:

------------------------------python 连接impala代码---------------------------------

from impala.dbapi import connect

if __name__ == '__main__':
    conn = connect(host='x.x.x.x', port=10000, database='dw', auth_mechanism='PLAIN',user='guest', password='guest')
    cur = conn.cursor()
    cur.execute("select * from dt.x_x_x limit 10")
    print(cur.fetchall())
 报如下错误
TypeError: can't concat str to bytes

------------------------------ 报如下错误---------------------------------

TypeError: can't concat str to bytes

------------------------------ 根据日志定位到错误的地方---------------------------------

lib\site-packages\thrift_sasl\__init__.py", line 94
header = struct.pack(">BI", status, len(body))
self._trans.write(header + body)
修改为 
header = struct.pack(">BI", status, len(body))
if(type(body) is str):
    body = body.encode()
self._trans.write(header + body)

三、再次连接,连接成功:在这里插入图片描述

你可能感兴趣的:(大数据)