我在W7机器上,使用Python(Anaconda发行版)使用Impyla软件包连接到我们的Hadoop集群中的Impala。 我的公司最近添加了Kerberos,最终破坏了我所拥有的。
在Kerberos之前:
from impala.dbapi import connect
conn = connect( host='localhost', port=21050)
cur = conn.cursor()
cur.execute('SHOW TABLES')
cur.fetchall()
在Kerberos之后
from impala.dbapi import connect
conn = connect( host='localhost', port=21050, use_kerberos=True,
kerberos_service_name='impala/myservername')
Traceback (most recent call last):
File "<ipython-input-13-068c7348729f>", line 2, in <module>
kerberos_service_name='impala/myservername')
File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\dbapi\__init__.py", line 47, in connect
ldap_password, use_kerberos, kerberos_service_name)
File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\_rpc\hiveserver2.py", line 193, in connect_to_impala
use_kerberos, kerberos_service_name)
File "C:\Users\x\AppData\Local\Continuum\Anaconda\lib\site-packages\impala\_rpc\hiveserver2.py", line 166, in _get_transport
import sasl
ImportError: No module named sasl
我尝试从CMD安装sasl:
>easy_install sasl
Searching for sasl
Reading https://pypi.python.org/simple/sasl/
Best match: sasl 0.1.3
Downloading https://pypi.python.org/packages/source/s/sasl/sasl-0.1.3.tar.gz#md5
=6db4ca3d4fb699cf126a6e6f2f516d8f
Processing sasl-0.1.3.tar.gz
Writing c:\users\x\appdata\local\temp\easy_install-zfqesn\sasl-0.1.3\setup
.cfg
Running sasl-0.1.3\setup.py -q bdist_egg --dist-dir c:\users\x\appdata\loc
al\temp\easy_install-zfqesn\sasl-0.1.3\egg-dist-tmp-cl0non
sasl/saslwrapper.cpp:21:23: fatal error: sasl/sasl.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'C:\\Users\\x\\AppData\\Loc
al\\Continuum\\Anaconda\\Scripts\\gcc.bat' failed with exit status 1
答案 0 :(得分:1)
我看到你正在运行Windows。你在运行cygwin还是其他一些python?
你试过了吗?
如果使用Cygwin,您是否尝试过安装libsasl2-devel?
从GIT存储库安装python-sasl,因为Cloudera似乎是jenkins environment的一部分吗?
pip install git + https://github.com/laserson/python-sasl.git@cython
应该做的神奇。
顺便说一下,您使用的代码已被弃用(根据当前的GitHub主机)。
使用
from impala.dbapi import connect
conn = connect( host='localhost', port=21050, auth_mechanism='GSSAPI',
kerberos_service_name='impala')
答案 1 :(得分:0)
我遇到了同样的问题,但是我通过安装正确版本的必需库来解决它。
使用pip
在python库下面安装:
six==1.12.0
bit_array==0.1.0
thrift==0.9.3
thrift_sasl==0.2.1
sasl==0.2.1
impyla==0.13.8
以下代码可用于python
版2.7
和3.4
。
import ssl
from impala.dbapi import connect
import os
os.system("kinit")
conn = connect(host='hostname.io',
port=21050,
use_ssl=True,
database='default',
user='urusername',
kerberos_service_name='impala',
auth_mechanism = 'GSSAPI')
cur = conn.cursor()
cur.execute('SHOW DATABASES;')
result=cur.fetchall()
for data in result:
print (data)