我已经安装好了
pip install thrift
pip install PyHive
pip install thrift-sasl
和
由于
pip install sasl
失败,我下载了sasl‑0.2.1‑cp27‑cp27m‑win_amd64.whl文件并将其安装在Windows 8.1 PC中。然后我写了这段代码,
from pyhive import hive
cursor = hive.connect('192.168.1.232', port=10000, auth='NONE')
cursor.execute('SELECT * from sample_07 LIMIT 5',async=True)
print cursor.fetchall()
这给出了错误:
Traceback (most recent call last):
File "C:/DigInEngine/scripts/UserManagementService/fd.py", line 37, in <module>
cursor = hive.connect('192.168.1.232', port=10000, auth = 'NONE')
File "C:\Python27\lib\site-packages\pyhive\hive.py", line 63, in connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\pyhive\hive.py", line 104, in __init__
self._transport.open()
File "C:\Python27\lib\site-packages\thrift_sasl\__init__.py", line 72, in open
message=("Could not start SASL: %s" % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2
这段代码给出了
from sqlalchemy import create_engine
engine = create_engine('hive://192.168.1.232:10000/default')
try:
connection = engine.connect()
except Exception, err:
print err
result = connection.execute('select * from sample_07;')
engine.dispose()
这个错误,
我已经从here下载了Hortonworks沙箱,并在单独的服务器中使用了它。
注意:我也经历过this,但可接受的答案对我不起作用,因为从 hive 导入ThriftHive会导致导入错误,尽管我已经安装了 hive 。所以我决定使用pyhive或sqlalchemy
如何连接到配置单元并轻松执行查询?
最佳答案
以下是在Windows上构建SASL的步骤,但是您的工作量可能会有所不同:很多取决于您的特定系统的路径和可用的库。
另请注意,这些说明特定于Python 2.7(我从问题路径中看到了该说明)。
高级别概述是您正在安装此项目:https://github.com/cyrusimap/cyrus-sasl。为此,您必须使用用于构建Python 2.7的旧式C++编译器。要使此功能生效,还有其他几个步骤。
的预构建步骤:
构建步骤:
git clone https://github.com/cyrusimap/cyrus-sasl
lib
子目录nmake /f ntmakefile STATIC=no prefix=C:\sasl64
nmake /f ntmakefile prefix=C:\sasl64 STATIC=no install
参见copy /B C:\sasl64\lib\libsasl.lib /B C:\sasl64\lib\sasl2.lib
pip install thrift_sasl --global-option=build_ext \ --global-option=-IC:\\sasl64\\include \ --global-option=-LC:\\sasl64\\lib
“包含”位置:
这是对这些相同步骤的引用,并带有一些其他注释和解释:http://java2developer.blogspot.co.uk/2016/08/making-impala-connection-from-python-on.html。
注意
所引用的指令还在
include
和win32\include
子目录中执行了步骤(8),您可能也必须这样做。关于python - pyhive,sqlalchemy无法连接到hadoop沙箱,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42210901/