通过以下方式连接到配置单元时出现套接字错误:hiveserver2-client.py

时间:2017-03-01 04:55:38

标签: hive fiware-cygnus

在尝试连接到配置单元之前,是否有任何人遇到此错误。

使用的示例代码(https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-ngsi/resources/hiveclients/python/hiveserver2-client.py):

import sys
import pyhs2
from pyhs2.error import Pyhs2Exception

# get the input parameters
if len(sys.argv) != 6:
    print 'Usage: python hiveserver2-client.py <hive_host> <hive_port> <db_name> <hadoop_user> <hadoop_password>'
    sys.exit()

hiveHost = sys.argv[1]
hivePort = sys.argv[2]
dbName = sys.argv[3]
hadoopUser = sys.argv[4]
hadoopPassword = sys.argv[5]

# do the connection
with pyhs2.connect(host=hiveHost,
                   port=hivePort,
                   authMechanism="PLAIN",
                   user=hadoopUser,
                   password=hadoopPassword,
                   database=dbName) as conn:
    # get a client
    with conn.cursor() as client:
        # create a loop attending HiveQL queries
        while (1):
            query = raw_input('remotehive> ')

            try:
                if not query:
                    continue

                if query == 'exit':
                    sys.exit()

                # execute the query
                client.execute(query)

                # get the content
                for row in client.fetch():
                    print row

            except Pyhs2Exception, ex:
                print ex.errorMessage

显示错误:

[centos@test]$ sudo python hiveserver2-client.py computing.cosmos.lab.fiware.org 10000 default USERNAME TOKEN
Traceback (most recent call last):
  File "hiveserver2-client.py", line 42, in <module>
    database=dbName) as conn:
  File "/usr/lib/python2.7/site-packages/pyhs2/__init__.py", line 7, in connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pyhs2/connections.py", line 46, in __init__
    transport.open()
  File "/usr/lib/python2.7/site-packages/pyhs2/cloudera/thrift_sasl.py", line 74, in open
    status, payload = self._recv_sasl_message()
  File "/usr/lib/python2.7/site-packages/pyhs2/cloudera/thrift_sasl.py", line 92, in _recv_sasl_message
    header = self._trans.readAll(5)
  File "/usr/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 60, in readAll
    chunk = self.read(sz - have)
  File "/usr/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 132, in read
    message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

1 个答案:

答案 0 :(得分:0)

你可以张贴你的代码吗?这看起来像某些auth机制或发送的凭据不是有效的。

根据您的设置

authMechanism= can be "PLAIN" or "KERBEROS"

相关问题