问题描述
我已经安装好了
pip install thrift
pip install PyHive
pip install thrift-sasl
由于pip install sasl
失败,因此我下载了文件并将其安装在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()
这个错误,
无法启动SASL:sasl_client_start(-4)中的错误SASL(-4):无可用的机制:无法找到回调:2
我已从下载Hortonworks沙箱,并在单独的服务器中使用它。
注意:我也经历了 ,但是可接受的答案对我来说不起作用,因为从蜂巢导入ThriftHive会导致导入错误,尽管我已经安装了蜂巢。 所以我决定使用pyhive或sqlalchemy
如何连接到配置单元并轻松执行查询?
1楼
使用pyhive时,不能将身份验证作为auth="NOSASL"
传递,而不是"None"
传递,因此您的代码应如下所示:
from pyhive import hive
cursor = hive.connect('192.168.1.232', port=10000, auth='NOSASL')
cursor.execute('SELECT * from sample_07 LIMIT 5',async=True)
print cursor.fetchall()
2楼
以下是在Windows上构建SASL的步骤,但是您的工作量可能会有所不同:很多取决于您特定系统的路径和可用的库。
另请注意,这些说明特定于Python 2.7(我从问题路径中看到了这些说明)。
高层概述是您正在安装此项目: : 。 为此,您必须使用用于构建Python 2.7的旧版C ++编译器。 还有其他几个步骤可以使它起作用。
预先建立步骤:
- 安装 。 使用默认安装路径-请注意接下来2个步骤的安装位置(以下列表中包含2个选项)
- 复制到适合您安装的任何包含位置
- 从在相同的include目录中创建一个unistd.h文件
建立步骤:
-
git clone https://github.com/cyrusimap/cyrus-sasl
- 从步骤1中打开与编译器一起安装的“ VS2013 x64本机工具命令提示符”
-
将目录更改为由步骤4创建的目录,然后更改为
lib
子目录 -
nmake /f ntmakefile STATIC=no prefix=C:\\sasl64
-
nmake /f ntmakefile prefix=C:\\sasl64 STATIC=no install
请参见下面的注释 -
copy /BC:\\sasl64\\lib\\libsasl.lib /BC:\\sasl64\\lib\\sasl2.lib
-
pip install thrift_sasl --global-option=build_ext \\ --global-option=-IC:\\\\sasl64\\\\include \\ --global-option=-LC:\\\\sasl64\\\\lib
“包含”位置:
- “ C:\\ Program Files(x86)\\ Common Files \\ Microsoft \\ Visual C ++ for Python \\ 9.0 \\ VC \\ include \\ stdint.h”
- “%USERPROFILE%\\ AppData \\ Local \\ Programs \\ Common \\ Microsoft \\ Visual C ++ for Python \\ 9.0 \\ VC \\ include”
这是对这些相同步骤的参考,并带有一些附加的注释和解释: : 。
注意 :所引用的指令还执行了include
和win32\\include
子目录中的步骤(8),您可能也必须这样做。