python上的Hive Server 2错误与hiveserver2连接

时间:2016-10-21 07:01:27

标签: python python-2.7 hadoop hive pyhive

我正在使用

Centos,Python2.7,hive 2.1,Hadoop 2.7.2,pyHive

这是代码

from pyhive import hive
from TCLIService.ttypes import TOperationState
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)

#status = cursor.poll().operationState
#while status in (TOperationState.INITIALIZED_STATE, TOperationState.RUNNI$
#    logs = cursor.fetch_logs()
#    for message in logs:
#        print message

# If needed, an asynchronous query can be cancelled at any time with:
# cursor.cancel()

# status = cursor.poll().operationState

#print cursor.fetchall()

当我在终端中运行python /usr/local/py/test5.py时显示....

Traceback (most recent call last):
File "/usr/local/py/test5.py", line 3, in <module>
cursor = hive.connect('localhost').cursor()
File "/usr/local/lib/python2.7/site-packages/pyhive/hive.py", line 63, in connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pyhive/hive.py", line 104, in __init__
self._transport.open()
File "/usr/local/lib/python2.7/site-packages/thrift_sasl/__init__.py", line 80, in open
status, payload = self._recv_sasl_message()
File "/usr/local/lib/python2.7/site-packages/thrift_sasl/__init__.py", line 98, in _recv_sasl_message
header = read_all_compat(self._trans, 5)
File "/usr/local/lib/python2.7/site-packages/thrift_sasl/six.py", line 31, in <lambda>
read_all_compat = lambda trans, sz: trans.readAll(sz)
File "/usr/local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 58, in readAll
chunk = self.read(sz - have)
File "/usr/local/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 120, in read
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

此后显示的Hive服务器错误日志...

ERROR [HiveServer2-Handler-Pool: Thread-41]: server.TThreadPoolServer (:()) - Thrift error occur$
org.apache.thrift.protocol.TProtocolException: Missing version in readMessageBegin, old client?
    at    org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:228)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:27)
    at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

此外,我曾尝试pyhs2获得同样的错误

出了什么问题?

由于

2 个答案:

答案 0 :(得分:0)

我用这些版本解决了这个错误:

Centos 7,Python2.7,hive 2.1,Hadoop 2.7.3和java java 1.7.0_91

使用impyla

它为我工作。

答案 1 :(得分:-1)

  

thrift.transport.TTransport.TTransportException:TSocket读取0个字节

我有同样的问题并通过

解决了
  1. 启动hiveserver2(how to start hiveserver2
  2. 修改您的端口。默认端口为10000,或者您可以将其更改为关注hive_site.xml