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

I am using impyla module to connect to kerberized hadoop cluster. I want to access

hiveserver2/hive but I was getting the below error:

test_conn.py

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()

Stacktrace:

[vagrant@localhost vagrant]$ python test_conn.py

Traceback (most recent call last):

File "test_conn.py", line 4, in

conn = connect(host=connection_string, port=21050, auth_mechanism="GSSAPI",kerberos_service_name='testuser@Myrealm.COM',password='testuser')

File "/usr/lib/python2.7/site-packages/impala/dbapi.py", line 147, in connect

auth_mechanism=auth_mechanism)

File "/usr/lib/python2.7/site-packages/impala/hiveserver2.py", line 758, in connect

transport.open()

File "/usr/lib/python2.7/site-packages/thrift_sasl/__init__.py", line 61, in open

self._trans.open()

File "/usr/lib64/python2.7/site-packages/thrift/transport/TSocket.py", line 101, in open

message=message)

thrift.transport.TTransport.TTransportException: Could not connect to hdp296m1.XXX.XXX.com:21050

testuser is my kerberos principal which I will be using to do kinit.

解决方案

Your connection appears to be incorrect.. Try,

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值