【问题标题】:Unable to connect to Hive2 using Python无法使用 Python 连接到 Hive2
【发布时间】:2018-02-04 20:48:01
【问题描述】:

使用 Python 连接到 Hive2 时,代码如下:

import pyhs2

with pyhs2.connect(host='localhost',
           port=10000,
           authMechanism="PLAIN",
           user='root',
           password='test',
           database='default') as conn:
with conn.cursor() as cur:
    #Show databases
    print cur.getDatabases()

    #Execute query
    cur.execute("select * from table")

    #Return column info from query
    print cur.getSchema()

    #Fetch table results
    for i in cur.fetch():
        print i

我遇到以下错误:

File
"C:\Users\vinbhask\AppData\Roaming\Python\Python36\site-packages\pyhs2-0.6.0-py3.6.egg\pyhs2\connections.py",
line 7, in <module>
    from cloudera.thrift_sasl import TSaslClientTransport ModuleNotFoundError: No module named 'cloudera'

已尝试herehere,但问题仍未解决。

这里是安装到现在的包:

bitarray0.8.1,certifi2017.7.27.1,chardet3.0.4,cm-api16.0.0,cx-Oracle6.0.1,future0.16.0,idna2.6,impyla0.14.0,JayDeBeApi1.1.1,JPype10.6.2,ply3.10,pure-sasl0.4.0,PyHive0.4.0,pyhs20.6.0,pyodbc4.0.17,requests2.18.4,sasl0.2.1,six1.10.0,teradata15.10.0.21,thrift0.10.0,thrift-sasl0.2.1,thriftpy0.3.9,urllib31.22

使用 Impyla 时出错:

Traceback (most recent call last):
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\Scripts\HiveConnTester4.py", line 1, in <module>
from impala.dbapi import connect
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\impala\dbapi.py", line 28, in <module>
import impala.hiveserver2 as hs2
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\impala\hiveserver2.py", line 33, in <module>
from impala._thrift_api import (
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\impala\_thrift_api.py", line 74, in <module>
include_dirs=[thrift_dir])
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\thriftpy\parser\__init__.py", line 30, in load
include_dir=include_dir)
File "C:\Users\xxxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\thriftpy\parser\parser.py", line 496, in parse
url_scheme))
thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol 'c'

【问题讨论】:

  • 我很惊讶这么多人突然抱怨 PyHive(目前已损坏 [2017 年 8 月])和 PyHS2(您显然无法正常工作)。改用 ImPyla。它由 Cloudera 维护。它有效。
  • @SamsonScharfrichter:我也曾在 Impyla 中尝试过,如上所述更新了错误日志
  • PySpark 怎么样?
  • 看起来你的 Python 堆栈中有一个恶意依赖项,它与所有 DB 驱动程序一起玩地狱......我建议你进行单独的、干净的 Python 安装,但使用 Anaconda;然后是 Impyla 的全新安装(使用 Anaconda 安装程序,参见anaconda.org/conda-forge/impyla)。如果该方法有效,那么您肯定会知道您当前的 Python 安装是罪魁祸首。
  • 回到基础:(1) 你在服务器端运行哪个版本的 Hive 以及 (2) 其他人是否成功连接到那个东西?

标签: python python-3.x hadoop hive cloudera


【解决方案1】:

thrift_sasl.py 正在尝试在 Python 3.0 中不再可用的 cStringIO。用 python 2 试试?

【讨论】:

  • 我们有使用python3+的需求
  • pysh2 不再维护。你尝试使用 PyHive 吗?
【解决方案2】:

您可能需要安装未发布版本的 thrift_sasl。试试:

pip install git+https://github.com/cloudera/thrift_sasl

【讨论】:

  • @Vinod 这有帮助吗?
  • 没有收到此错误“无法连接到 github.com 端口 443:超时”
  • 最后一个错误提示您位于防火墙后面 - 这就是您访问端口 443 时超时的原因。将 https: 更改为 http: 并重试 - 端口 80 可能已打开。
  • 更改为http后出现此错误“致命:无法访问'github.com/cloudera/thrift_sasl':无法连接到github.com端口80:超时命令“git clone -q github.com/cloudera/thrift_saslC: \Users\xxxx\AppData\Local\Temp\pip-5_9y1ynj-build”失败,错误代码为 128,无”
【解决方案3】:

如果您愿意学习 PySpark,那么您只需设置 hive.metastore.uris 属性以指向 Hive Metastore 地址,就可以开始了。

最简单的方法是从集群中导出hive-site.xml,然后在spark-submit 期间传递--files hive-site.xml

(我还没有尝试过运行独立的 Pyspark,所以 YMMV)

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多