I am trying to access hive using pyhs2
. I tried the following code:
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
I am getting the following error:
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
I am getting the exact error when I try with hive utils. I have checked sasl installation. Do I need to make any changes to the hive-site.xml in hive? If yes where do I need to create it? Am I missing out something?
1- Figure out the IP address of the localhost using (on Linux):
2- Change localhost to the actual ip
I would also suggest that you double check which host Hive is on. If you are using hortonworks, on Ambari, go to
Hive
, thenConfigs
and check the host there.Edit (adding another suggestion):
Your username and password most likely aren't
None
. To get your username and password, checkhive-site.xml
and look at the values injavax.jdo.option.ConnectionUserName
andjavax.jdo.option.ConnectionPassword
. If you can't find anything, try an empty string as the password (as opposed to None), andhive
or empty string as the username i.e. try these one by one: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')
Note that I also changed
authMechanism
to"PLAIN"