我在远程服务器上安装了以下必要的包,以便通过python访问hive。
python 2.7.6版,
python开发工具,
pyhs2号,
sasl-0.1.3,
节俭-0.9.1,
Hive-0.1.0
下面是访问配置单元的python脚本。
# !/usr/bin/env python
import pyhs2 as hive
import getpass
DEFAULT_DB = 'camp'
DEFAULT_SERVER = '10.25.xx.xx'
DEFAULT_PORT = 10000
DEFAULT_DOMAIN = 'xxx.xxxxxx.com'
# Get the username and password
u = raw_input('Enter PAM username: ')
s = getpass.getpass()
# Build the Hive Connection
connection = hive.connect(host=DEFAULT_SERVER, port=DEFAULT_PORT, authMechanism='LDAP', user=u + '@' + DEFAULT_DOMAIN, password=s)
# Hive query statement
statement = "select * from camp.test"
cur = connection.cursor()
# Runs a Hive query and returns the result as a list of list
cur.execute(statement)
df = cur.fetchall()
这是我得到的结果:
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 74, in open
File "build/bdist.linux-x86_64/egg/pyhs2/cloudera/thrift_sasl.py", line 92, in _recv_sasl_message
File "build/bdist.linux-x86_64/egg/thrift/transport/TTransport.py", line 58, in readAll
File "build/bdist.linux-x86_64/egg/thrift/transport/TSocket.py", line 118, in read
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes
在执行脚本之后,我没有看到输出中有任何错误,但是在屏幕上我没有看到任何查询结果。我不知道为什么它没有显示任何查询结果,配置单元服务器ip、端口、用户和密码是否正确。我还验证了配置单元服务器和远程服务器之间的连接,没有连接问题。
2条答案
按热度按时间izkcnapc1#
我已经通过以下方法获得了访问权限
6qqygrtg2#
尝试使用以下代码: