Hive - python connection error

2019-09-06 10:30发布

Here is code :

#!/usr/bin/env python
import pyhs2
try:
with pyhs2.connect(host='localhost',
           port=10001,
           authMechanism="PLAIN",
           user='root',
           password='test',
           database='test') as conn:
    with conn.cursor() as cur:
        #Show databases
        print cur.getDatabases()

        #Execute query
        cur.execute("select * from raw_stats")

        #Return column info from query
        print cur.getSchema()

        #Fetch table results
        for i in cur.fetch():
            print i

except Thrift.TException, tx:
print '%s' % (tx.message)   

Error!

Traceback (most recent call last): File "/usr/local/py/test.py", line 8, in database='default') as conn: File "/usr/lib/python2.6/site-packages/pyhs2/init.py", line 7, in connect return Connection(*args, **kwargs) File "/usr/lib/python2.6/site-packages/pyhs2/connections.py", line 46, in init transport.open() File "/usr/lib/python2.6/site-packages/pyhs2/cloudera/thrift_sasl.py", line 55, in open self._trans.open() File "/usr/lib64/python2.6/site-packages/thrift/transport/TSocket.py", line 101, in open message=message) thrift.transport.TTransport.TTransportException: Could not connect to localhost:10001

1条回答
萌系小妹纸
2楼-- · 2019-09-06 11:07

It resolved by starting hiveServer2 service and changing the port 10000.

查看更多
登录 后发表回答