【问题标题】:pyhive, sqlalchemy can not connect to hadoop sandboxpyhive,sqlalchemy 无法连接到 hadoop 沙箱
【发布时间】:2017-02-13 18:23:31
【问题描述】:

我已经安装了,

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

这个错误,

无法启动 SASL:sasl_client_start (-4) 中的错误 SASL(-4):否 可用机制:找不到回调:2

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

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

如何轻松连接到 hive 并执行查询?

【问题讨论】:

    标签: python hadoop hive sqlalchemy pyhive


    【解决方案1】:

    以下是在 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 Tools 命令提示符”
    3. 将目录更改为第 4 步创建的目录,然后是 lib 子目录
    4. nmake /f ntmakefile STATIC=no prefix=C:\sasl64
    5. nmake /f ntmakefile prefix=C:\sasl64 STATIC=no install 请参阅下面的注释
    6. copy /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),您可能也必须这样做。

    【讨论】:

    • 感谢您的明确回答和您的宝贵时间。如果可行,我会试试这个并接受答案。 :)
    • 但错误提示无法启动 SASL。它并没有说没有它..无论如何我会试试你说的
    • 对 python 3 有什么建议吗?
    【解决方案2】:

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

    【讨论】:

    • 我认为这不是身份验证问题,我改用 linux 让开发人员生活更轻松
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多