005 python连接hive

本文介绍了如何在Python环境中配置并连接Hive,包括Hive的安装,解决sasl安装问题,提供Python连接Hive的测试代码,以及针对TTransportException错误的解决办法,最后给出了相关参考资料。
摘要由CSDN通过智能技术生成
环境安装
  1. hive
    hive 安装包配置
  2. python配置hive环境
    pip install sasl
    pip install thrift
    pip install thrift-sasl
    pip install PyHive
    
    注:安装sasl的时候可能会报错,导致安装不上,这个时候去sasl下载地址下载配置版本的sasl
    # 安装适配版本的whl
    pip install sasl-0.2.1-cp37-cp37m-win_amd64.whl
    
python 连接hive测试
  1. 连接代码
    from pyhive import hive
    
    def main():
        conn = hive.Connection(
            host='192.168.1.18',
            port=10000,
            username='hive',
            database='default',
            auth='NOSASL'
        )
    
        cursor = conn.cursor()
        cursor.execute('show databases')
        res = cursor.fetchall()
        for x in res:
        	print(x)
        conn.close()
        
    if __name__ == "__main__":
        main()
    
问题解决
  1. thrift.transport.TTransport.TTransportException: Could not start SASL: b’Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2’
    conn = hive.Connection(
    	host='192.168.1.18',
    	port=10000,
    	username='hive',
    	database='default',
    	auth='NOSASL'  # 添加该项,则不会报上面的错误
    )
    
  2. 若连接不报错,也不返回,则需要修改hive-site.xml文件-
    # 添加
    <property>
      <name>hive.server2.authentication</name>
      <value>NOSASL</value>
      <description>
        Expects one of [nosasl, none, ldap, kerberos, pam, custom].
        Client authentication types.
          NONE: no authentication check
          LDAP: LDAP/AD based authentication
          KERBEROS: Kerberos/GSSAPI authentication
          CUSTOM: Custom authentication provider
                  (Use with property hive.server2.custom.authentication.class)
          PAM: Pluggable authentication module
          NOSASL:  Raw transport
      </description>
    </property>
    
    重启hiveserver2。
参考

1. pycharm使用pyhive连接hive
2. Python连接Hive(基于PyHive)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值