Pyhive、SASL 和 Python 3.5

Pyhive, SASL and Python 3.5

我尝试按照此处所述设置配置单元连接:How to Access Hive via Python? 使用配置单元。与 python 3.5.2 的连接(安装在 cloudera Linux BDA 上)但 SASL 包似乎导致问题。我在论坛上看到 SASL 仅与 2.7 python 兼容。那正确吗?我miss/do错了什么?

from pyhive import hive
conn = hive.Connection(host="myserver", port=10000)
import pandas as pd

错误信息

TTransportException Traceback (most recent call last)
in ()
1 from pyhive import hive
2 #conn = hive.Connection(host="myserver", port=10000)
----> 3 conn = hive.Connection(host="myserver")
4 import pandas as pd

/opt/anaconda3/lib/python3.5/site-packages/pyhive/hive.py in init(self, host, port, username, database, auth, configuration)
102
103 try:
--> 104 self._transport.open()
105 open_session_req = ttypes.TOpenSessionReq(
106 client_protocol=protocol_version,

/opt/anaconda3/lib/python3.5/site-packages/thrift_sasl/init.py in open(self)
70 if not ret:
71 raise TTransportException(type=TTransportException.NOT_OPEN,
---> **72 message=("Could not start SASL: %s" % self.sasl.getError()))**
73
74 # Send initial response

TTransportException: TTransportException(message="Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: No worthy mechs found'", type=1)

检查是否安装了所有依赖项:

gcc-c++
python-devel.x86_64
cyrus-sasl-devel.x86_64

(假设你在 windows)

我们(应该说是 IT 团队)找到解决方案

升级python包thrift(到0.10.0版)和PyHive(到0.3.0版)不知道为什么我们使用的版本不是最新的。

添加了以下内容:

<property>
<name>hive.server2.authentication</name>
<value>NOSASL</value>
</property>

到 Cloudera Manager 中的以下 Hive 配置参数:

配置单元的 HiveServer2 高级配置片段(安全阀)-site.xml hive-site.xml 的 Hive 客户端高级配置片段(安全阀)是必要的,这样 HUE 才能工作

from pyhive import hive
conn = hive.Connection(host="myserver", auth='NOSASL')
import pandas as pd
import sys

df = pd.read_sql("SELECT * FROM my_table", conn) 
print(sys.getsizeof(df))
df.head()

在没有 problem/error 的情况下工作。

最好的, 汤姆