windows10上通过python3远程连接hive
发布日期:2021-05-15 21:32:07 浏览次数:32 分类:技术文章

本文共 1706 字,大约阅读时间需要 5 分钟。

注意:impyla 既可以连接impala, 也可以连接hive

环境 : windows10

python版本:3.6
hive版本:1.1

impyla安装过程

安装依赖

pip3 install bit_array
pip3 install thrift
pip3 install thriftpy
pip3 install pure_sasl
pip install --no-deps thrift-sasl==0.2.1
安装impyla
pip3 install impyla

连接Hive

# -*-coding:utf-8 -*-from impala.dbapi import connectconn = connect(host='ip', port=10000, database='default', user='hive', password='hive', auth_mechanism="PLAIN")cur = conn.cursor()cur.execute('show tables')print(cur.fetchall())

注意事项

1.重点不要安装sasl,否则会提示报错

卸载方式:pip3 uninstall sasl
2.在安装过程中,如果出现包安装失败的情况,可以下载whl包进行安装,下载链接:https://www.lfd.uci.edu/~gohlke/pythonlibs/
安装方式:pip3 install 包的绝对路径
3.如果在安装过程中,出现任何包安装失败的问题,可以先将之前所有安装过的包统统卸载,再按顺序依次安装一次

问题集锦

  1. impyla (0.14.0) ERROR - ‘TSocket’ object has no attribute ‘isOpen’
    这个问题的原因是thrift-sasl版本过高导致的,将其换成0.2.1的版本即可
    pip3 install thrift-sasl==0.2.1
  2. thriftpy2.protocol.exc.TProtocolException: TProtocolException(type=4)
    这是由于auth_mechanism设置的问题导致的,加上或将其改为auth_mechanism="PLAIN"即可
  3. TypeError: can’t concat str to bytes
    修改 thrift-sasl init.py,在第94行之前加上以下语句即可:
def _send_message(self, status, body):    header = struct.pack(">BI", status, len(body))    if (type(body) is str):      body = body.encode()    self._trans.write(header + body)    self._trans.flush()
  1. thrift.transport.TTransport.TTransportException: Could not start SASL: b’Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2’
    这是Windows下采用pyhive连接方式提出的错误,正如前言所述,可能需要修改对应的配置文件,也可能sasl根本就不支持Windows,建议改用impyla形式连接
  2. thriftpy.parser.exc.ThriftParserError: ThriftPy does not support generating module with path in protocol ‘c’
    修改thriftpy包下\parser\parser.py"中第488行代码,将"if url_scheme == ‘’:" 修改为"if len(url_scheme) <=1:"即可

转载地址:https://blog.csdn.net/qq_30868737/article/details/108009736 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:XGBoost学习(二):介绍及安装
下一篇:XGBoost学习(一):原理

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月18日 14时45分15秒