【问题标题】:PyHive with Kerberos throws Authentication error after few calls使用 Kerberos 的 PyHive 在几次调用后引发身份验证错误
【发布时间】:2020-03-13 01:52:02
【问题描述】:

我正在尝试使用 Python (PyHive Lib) 连接到 Hive 以读取一些数据,然后我进一步将其连接到 hive Flask显示在仪表板中。

对于很少调用 hive 来说一切正常,但不久之后我就遇到了以下错误。

Traceback (most recent call last):
  File "libs/hive.py", line 63, in <module>
    cur = h.connect().cursor()
  File "libs/hive.py", line 45, in connect
    kerberos_service_name='hive')
  File "/home1/igns/git/emsr/.venv/lib/python2.7/site-packages/pyhive/hive.py", line 94, in connect
    return Connection(*args, **kwargs)
  File "/home1/igns/git/emsr/.venv/lib/python2.7/site-packages/pyhive/hive.py", line 192, in __init__
    self._transport.open()
  File "/home1/igns/git/emsr/.venv/lib/python2.7/site-packages/thrift_sasl/__init__.py", line 79, in open
    message=("Could not start SASL: %s" % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-1) SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure.  Minor code may provide more information (No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_cdc995595290_51CD7j))

以下是我的代码

from pyhive import hive
class Hive(object):
    def connect(self):
        return hive.connect(host='hive.hadoop-prod.abc.com',
                            port=10000,
                            database='temp',
                            username='gaurang.shah',
                            auth='KERBEROS',
                            kerberos_service_name='hive')


if __name__ == '__main__':

    h = Hive()
    cur = h.connect().cursor()
    cur.execute("select * from temp.migration limit 1")
    res = cur.fetchall()
    print res

调用脚本

source .venv/bin/activate
for i in {1..50}
do
    python get_hive_data.py
    sleep 300
done

观察 当它工作时,当我执行 klist 时,我可以在服务主体中看到 hive,但是,当我看到上述错误消息时却没有。

Klist 工作时

Ticket cache: FILE:/tmp/krb5cc_cdc995595290_XyMnhu
Default principal: gaurang.shah@ABC.COM

Valid starting       Expires              Service principal
12/04/2018 14:37:28  12/05/2018 00:37:28  krbtgt/ABC.COM@ABC.COM
    renew until 12/05/2018 14:37:24
12/04/2018 14:39:06  12/05/2018 00:37:28  hive/hive_server.ABC.COM@ABC.COM
    renew until 12/05/2018 14:37:24

Klist 不工作时

Ticket cache: FILE:/tmp/krb5cc_cdc995595290_XyMnhu
Default principal: gaurang.shah@ABC.COM

Valid starting       Expires              Service principal
12/04/2018 14:37:28  12/05/2018 00:37:28  krbtgt/ABC.COM@ABC.COM
    renew until 12/05/2018 14:37:24

更新:

所以我不认为这是在某个电话之后,但我认为是在某个时间之后。 (我想一小时)。我将 睡眠时间 更改为 3600 秒,就在第一次通话后,我开始出错。

这很奇怪,hive/hive_server.ABC.COM@ABC.COM 的票有效期为 7 天

【问题讨论】:

  • @karma4917 这没用,他们使用的是pys2,而我使用的是pyhive。而且我能够成功运行。只是过了一段时间它开始给出错误。

标签: python hive kerberos pyhive


【解决方案1】:

我知道这是一篇旧帖子。但是,如果您每次通话时都建立新连接,则应该解决问题。

from pyhive import hive
class Hive(object):
    def connect(self):
        return hive.connect(host='hive.hadoop-prod.abc.com',
                            port=10000,
                            database='temp',
                            username='gaurang.shah',
                            auth='KERBEROS',
                            kerberos_service_name='hive')


if __name__ == '__main__':
    def newConnect(query):
       h = Hive()
       cur = h.connect().cursor()
       cur.execute(query)
       res = cur.fetchall()
       return res

    myConnectionAndResults = newConnect("select * from temp.migration limit 1")
    print myConnectionAndResults

【讨论】:

  • 错误:thrift.transport.TTransport.TTransportException:TSocket 读取 0 个字节
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-22
  • 1970-01-01
  • 2016-03-24
  • 2011-04-03
  • 1970-01-01
相关资源
最近更新 更多