码迷,mamicode.com
首页 > 编程语言 > 详细

【大数据】windows 下python3连接hive

时间:2020-05-27 18:25:56      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:cut   style   sasl   title   --   sch   auth   string   dep   

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

环境 : windows10

python版本:3.6

hive版本:1.1 

亲测可用!

 

impyla安装过程

安装依赖

pip install bit_array

pip install thrift

pip install thriftpy

pip install pure_sasl

pip install --no-deps thrift-sasl==0.2.1

安装impyla

pip install impyla

连接Hive

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

注意事项

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

卸载方式:pip uninstall sasl

2.在安装过程中,如果出现包安装失败的情况,可以下载whl包进行安装,下载链接:https://www.lfd.uci.edu/~gohlke/pythonlibs/

安装方式:pip install 包的绝对路径

3.如果在安装过程中,出现任何包安装失败的问题,可以先将之前所有安装过的包统统卸载,再按顺序依次安装一次

 

 

问题集锦

impyla (0.14.0) ERROR - ‘TSocket‘ object has no attribute ‘isOpen‘

这个问题的原因是thrift-sasl版本过高导致的,将其换成0.2.1的版本即可

pip install thrift-sasl==0.2.1

thriftpy2.protocol.exc.TProtocolException: TProtocolException(type=4)

这是由于auth_mechanism设置的问题导致的,加上或将其改为auth_mechanism="PLAIN"即可

TypeError: can’t concat str to bytes

修改 thrift-sasl init.py,在第94行之前加上以下语句即可:

if (type(body) is str):
    body = body.encode()

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形式连接

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://www.aitolearn.com/article/9a06a8e1ff5e4252aa2373eb3cc4fed8

【大数据】windows 下python3连接hive

标签:cut   style   sasl   title   --   sch   auth   string   dep   

原文地址:https://www.cnblogs.com/TurboWay/p/12975034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!