使用python模块impy连接到Kerberized hadoop集群

2024-06-29 01:05:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用impyla模块连接到kerberized hadoop集群。我想访问
hiveserver2/hive,但我收到以下错误:

试验_连接件在

from impala.dbapi import connect
import os
connection_string = 'hdp296m1.XXX.XXX.com'
conn = connect(host=connection_string, port=21050,auth_mechanism="GSSAPI",kerberos_service_name='testuser@Myrealm.COM',password='testuser')
cursor = conn.cursor()
cursor.execute('select count(*) form t_all_types_simple_t')
print cursor.description
results = cursor.fetchall()

堆栈跟踪:

^{pr2}$

testuser是我的kerberos主体,我将使用它来执行kinit。在


Tags: 模块importhadoopstringconnect集群kerberosconnection
1条回答
网友
1楼 · 发布于 2024-06-29 01:05:30

您的连接似乎不正确。。试试看

from impala.dbapi import *
import sys, os
# set your parms
host=os.environ.get("CDH_HIVE",'x.x.x.x')
port=os.environ.get("CDH_HIVE_port",'10000')
auth_mechanism=os.environ.get("CDH_auth",'GSSAPI')
user='hive' 
db='mydb' 
# No password use kinit 
password=''
# hive is principal with krb
kbservice='hive'  

class Hive:

    def __init__(self,db):
        self.database=db
        self.__conn = connect(host=host,
                            port=port,
                            auth_mechanism=auth_mechanism,
                            user=user,
                            password=password,
                            database=db,
                            kerberos_service_name=kbservice
                            )


        self.__cursor = self.__conn.cursor()


h = Hive(db)

相关问题 更多 >