python3.8 连接Hive ubuntu踩坑实录

centos

yum install gcc-c++ python-devel.x86_64 cyrus-sasl-devel.x86_64  
pip install pyhs2   

ubuntu

sudo apt-get install libsasl2-dev libxml2-dev libxslt1-dev python-dev zlib1g-dev libevent-dev

sudo pip install lxml keyring keyrings.alt setuptools wheel
pip install --upgrade setuptools wheel keyring keyrings.alt
pip install six bit_array cython pyhs2 sasl thriftpy thrift_sasl

如果报错:'TSocket' object has no attribute 'isOpen' 则是thrift-sasl的版本太高了(0.3.0),故将thrift-sasl的版本降级到0.2.1

pip install thrift-sasl==0.2.1 impyla

报错:ThriftPy does not support generating module with path in protocol 'c'

主要是源码在解析url的时候出现错误,解决方法如下:
修改windows端中的parser 代码,笔者代码位置如下: C:\ProgramData\Anaconda2\Lib\site-packages\thriftpy\parser
修改其中的488行为如下情况:
#if url_scheme == '':
if len(url_scheme) <= 1:
然后重新运行即可。

报错:thriftpy.transport.TTransportException: TTransportException(message="Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'", type=1)

其中,authMechanism的值取决于hive-site.xml里的配置
<name>hive.server2.authentication</name>
<value>NOSASL</value>
默认为NONE,另外还可以为’NOSASL’, ‘PLAIN’, ‘KERBEROS’, ‘LDAP’. 
了解导auth_mechanism 这个参数的取值可以是:’NOSASL’, ‘PLAIN’, ‘KERBEROS’, ‘LDAP’.

需要查看hive的配置文件hive-site.xml里面的取值,于是找到对应文件:
取值为NONE,修改测试里的参数:
from impala.dbapi import connect
conn = connect(host='*',port = 10000,auth_mechanism='NONE')
cur=conn.cursor()
cur.execute('SHOW databases;')
print(cur.fetchall())
cur.close()
conn.close()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章