Hive - python连接错误

时间:2016-10-17 14:22:57

标签: python hadoop hive

以下是代码:

#!/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)   

错误!

  

回溯(最近一次调用最后一次):文件" /usr/local/py/test.py" ;,行   8,在数据库中='默认')为conn:File   " /usr/lib/python2.6/site-packages/pyhs2/ init .py",第7行,在   连       return Connection(* args,** kwargs)File" /usr/lib/python2.6/site-packages/pyhs2/connections.py" ;,第46行,in   的初始化       transport.open()File" /usr/lib/python2.6/site-packages/pyhs2/cloudera/thrift_sasl.py" ;, line   55,在公开场合       self._trans.open()File" /usr/lib64/python2.6/site-packages/thrift/transport/TSocket.py" ;, line   101,在公开场合       message = message)thrift.transport.TTransport.TTransportException:无法连接到localhost:10001

1 个答案:

答案 0 :(得分:0)

通过启动hiveServer2服务并更改端口10000来解决此问题。