【问题标题】:How to connect to hive using python pyhs2?如何使用 python pyhs2 连接到 hive?
【发布时间】:2015-11-15 10:27:48
【问题描述】:

我正在尝试使用pyhs2 访问配置单元。我尝试了以下代码:

example.py

import pyhs2
conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default')
with conn.cursor() as cur:
        cur.execute("select * from table")
        for i in cur.fetch():
            print i

我收到以下错误:

    Traceback (most recent call last):
 File "example.py", line 2, in <module> conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default')
      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 55, in open
      File "build/bdist.linux-x86_64/egg/thrift/transport/TSocket.py", line 101, in open
    thrift.transport.TTransport.TTransportException: Could not connect to localhost:10000

当我尝试使用 hive utils 时,我得到了确切的错误。我已经检查了 sasl 安装。我需要对 hive 中的 hive-site.xml 进行任何更改吗?如果是,我需要在哪里创建它?我错过了什么吗?

【问题讨论】:

  • 您在使用 hortonworks 吗?您可以访问 Ambari 吗?
  • 不,我没有使用 hortonworks

标签: python hadoop hive thrift


【解决方案1】:

1- 使用(在 Linux 上)找出 localhost 的 IP 地址:

hostname -I

2-将localhost更改为实际ip

我还建议您仔细检查 Hive 所在的主机。如果您在 Ambari 上使用 hortonworks,请转到 Hive,然后转到 Configs 并检查那里的主机。

编辑(添加另一个建议):

您的用户名和密码很可能不是None。要获取您的用户名和密码,请检查 hive-site.xml 并查看 javax.jdo.option.ConnectionUserNamejavax.jdo.option.ConnectionPassword 中的值。如果找不到任何内容,请尝试使用空字符串作为密码(而不是 None),并使用 hive 或空字符串作为用户名,即逐一尝试:

conn = pyhs2.connect(host='localhost', port=10000,authMechanism='PLAIN', user='hive', password='',database='default')

conn = pyhs2.connect(host='localhost', port=10000,authMechanism='PLAIN', user='', password='',database='default')

请注意,我还将authMechanism 更改为"PLAIN"

【讨论】:

  • 好的,我编辑了我的答案以建议可能有效的不同用户名和密码组合。很可能不是无
  • @highonprogramming 如何连接到远程服务器?我是否需要在 CLI 上运行任何命令(例如启动服务器)?
  • @Mrunmayee 您需要从命令行“hive —service hiveserver2”启动您的配置单元服务器
  • @highonprogramming 远程服务器 - 不。我只能连接到本地主机上的配置单元。
  • 我只是放了远程服务器的ip。尝试 ping 您使用的 ip 并确保它是正确的。也许您使用的是私有 ip 而不是公共 ip 或类似的东西。
猜你喜欢
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-12
  • 2019-06-09
  • 1970-01-01
相关资源
最近更新 更多