1,安装对应依赖
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
如果安装不上sasl,可以尝试 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 寻找对应py版本的whl文件安装
2,连接hive
conn = hive.Connection(host='hive地址', port=10000, username='username')
cursor = conn.cursor()
sql = "show tables"
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
conn.close()
3,常见报错
thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'
解决方案:
1.寻找到sasl的安装位置,一般来说是如下位置
C:\Users\你计算机的用户名字\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\sasl\sasl2
2. C盘新建文件夹 C:\CMU\bin\sasl2
3. 将第一步中的saslPLAIN.dll拷贝至第二步新建的文件夹中
4. 问题应该得到解决