Pyhon 链接 hive数据库,需要导入的jar包

Pyhon 链接 hive数据库,需要导入的jar包

1.环境准备
win 10 64bit
python 37

2.jar下载
说明:.whl文件到http://www.lfd.uci.edu/~gohlke/pythonlibs/下载相应的python和windows版本
下载本地:D:\Ddocument

3.操作步骤
a.cmd下
b.切换到python目录下:cd C:\Users\tdc\AppData\Local\Programs\Python\Python37 \Scripts
c.依次执行
pip install six
pip install bit_array
pip install thriftpy ## thrift (on Python 2.x) or thriftpy (on Python 3.x)
pip install D:\Ddocument\sasl-0.2.1-cp37-cp37m-win_amd64.whl
pip install thrift_sasl
pip install D:\Ddocument\bitarray-1.2.0-cp37-cp37m-win_amd64.whl
pip install impyla

4.代码
from impala.dbapi import connect
from impala.util import as_pandas

conn = connect(host='***', port=10000, auth_mechanism='PLAIN', user='***', password='***', database='***')
cursor = conn.cursor()
cursor.execute('show databases')
print(as_pandas(cursor)

5.运行报错
TypeError: can’t concat str to bytes

修改文件
定位到 \Lib\site-packages\thriftpy\parser\parser.py的
原来:
if url_scheme == '':
with open(path) as fh:
    data = fh.read()
elif url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
raise ThriftParserError('ThriftPy does not support generating module '
                        'with path in protocol \'{}\''.format(
                            url_scheme))
                        
修改为:
if url_scheme == '':
with open(path) as fh:
    data = fh.read()
elif url_scheme in ('c', 'd','e','f''):
with open(path) as fh:
    data = fh.read()
elif url_scheme in ('http', 'https'):
data = urlopen(path).read()
else:
raise ThriftParserError('ThriftPy does not support generating module '
                        'with path in protocol \'{}\''.format(
                            url_scheme))

6.运行报错:
TypeError: can’t concat str to bytes

修改文件:
定位到定位到 \Lib\site-packages\thrift_sasl\__init__.py的
原来:
...
header = struct.pack(">BI", status, len(body))
self._trans.write(header + body)
...

修改为:
...
header = struct.pack(">BI", status, len(body))
if(type(body) is str):
body = body.encode() 
self._trans.write(header + body)
...

7.运行成功

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值