python - pyhive、sqlalchemy 无法连接到 hadoop 沙箱

标签 python hadoop hive sqlalchemy pyhive

我已经安装了,

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()

这个错误,

Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2

我已经从 here 下载了 Hortonworks 沙盒并在单独的服务器中使用它。

注意:我经历了this也但是接受的答案对我不起作用,因为从 hive 导入 ThriftHive 会出现导入错误,尽管我已经 pip 安装了 hive。所以我决定使用pyhive或者sqlalchemy

如何连接到配置单元并轻松执行查询?

最佳答案

以下是在 Windows 上构建 SASL 的步骤,但您的里程可能会有所不同:其中很多取决于您特定系统的路径和可用库。

另请注意,这些说明特定于 Python 2.7(我从问题的路径中看到您正在使用它)。

高级概述是您正在安装此项目:https://github.com/cyrusimap/cyrus-sasl .为此,您必须使用用于构建 Python 2.7 的遗留 C++ 编译器。还有几个其他步骤可以让它发挥作用。

预构建步骤:

  1. 安装 Microsoft Visual C++ Compiler for Python 2.7 .使用默认安装路径 - 记下接下来 2 个步骤的安装位置(下面的列表中包含 2 个选项)
  2. 复制this file到适合您安装的任何包含位置
  3. this answer 制作一个 unistd.h 文件在同一个包含目录中

构建步骤:

  1. git clone https://github.com/cyrusimap/cyrus-sasl
  2. 打开与第 1 步中的编译器一起安装的“VS2013 x64 native 工具命令提示符”
  3. 将目录切换到第 4 步创建的目录,然后是 lib 子目录
  4. nmake/f ntmakefile STATIC=no prefix=C:\sasl64
  5. nmake/f ntmakefile prefix=C:\sasl64 STATIC=no install 请参阅下面的注释
  6. 复制/B C:\sasl64\lib\libsasl.lib/B C:\sasl64\lib\sasl2.lib
  7. 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”

以下是对这些相同步骤的引用,以及一些额外的注释和解释:http://java2developer.blogspot.co.uk/2016/08/making-impala-connection-from-python-on.html .

注意 引用的指令还在 includewin32\include 子目录中执行了步骤 (8),您可能也必须这样做。

关于python - pyhive、sqlalchemy 无法连接到 hadoop 沙箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42210901/

相关文章:

python - 在 python 中拟合线性变换

hadoop - Apache pig : FLATTEN and parallel execution of reducers

hadoop - 无法以远程模式运行Hive Metastore

hadoop - 配置单元创建失败:资源不可用异常

python - 谁能告诉我为什么我的 else 语句出现无效语法错误?

python - 根据 Pandas 中的多个条件过滤行

hadoop - 生成 HDFS 序列文件

sql - 如何在 hive 中获取字符串中的元素?

python - 当你调用一个包含 yield 的函数时会发生什么?

amazon-web-services - 当我们可以直接将数据写入s3位置时,为什么需要distcp命令将数据从hdfs复制到s3?