我正在尝试使用pyhs2访问蜂巢.我尝试了以下代码:
example.py
import pyhs2
conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default')
with conn.cursor() as cur:
cur.execute("select * from table")
for i in cur.fetch():
print i
我收到以下错误:
Traceback (most recent call last):
File "example.py", line 2, in <module> conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default')
File "build/bdist.linux-x86_64/egg/pyhs2/__init__.py", line 7, in connect
File "build/bdist.linux-x86_64/egg/pyhs2/connections.py", line 46, in __init__
File "build/bdist.linux-x86_64/egg/pyhs2/cloudera/thrift_sasl.py", line 55, in open
File "build/bdist.linux-x86_64/egg/thrift/transport/TSocket.py", line 101, in open
thrift.transport.TTransport.TTransportException: Could not connect to localhost:10000
当我尝试蜂巢工具时,我得到确切的错误.我检查了sasl安装.我是否需要对hive中的hive-site.xml进行任何更改?如果是,我需要在哪里创建它?我错过了什么吗?
解决方法:
1-使用(在Linux上)找出本地主机的IP地址:
hostname -I
2-将本地主机更改为实际的IP
我还建议您仔细检查Hive在哪个主机上.如果您使用的是hortonworks,请在Ambari上转到Hive,然后转到Configs并在那里检查主机.
编辑(添加另一个建议):
您的用户名和密码很可能不是“无”.要获取用户名和密码,请检查hive-site.xml并查看javax.jdo.option.ConnectionUserName和javax.jdo.option.ConnectionPassword中的值.如果找不到任何内容,请尝试使用一个空字符串作为密码(与“无”相对),并配置一个蜂巢或空字符串作为用户名,即,一一尝试:
conn = pyhs2.connect(host =’localhost’,port = 10000,authMechanism =’PLAIN’,user =’hive’,password =”,database =’default’)
conn = pyhs2.connect(host =’localhost’,port = 10000,authMechanism =’PLAIN’,user =”,password =”,database =’default’)
请注意,我还将authMechanism更改为“ PLAIN”