Python创建带Kerberos认证的impala连接方法

公司impala最近打了补丁,变为待认证的连接

jdbc:impala://xxxx.xxxx.xxxx.xxxx:xxxx/xxxx;AuthMech=3;UID=UserName;PWD=Password

尝试将原来用sqlalchemy创建engine的方法进行修改:

import sqlalchemy
engine = sqlalchemy.create_engine('impala://xxxx.xxxx.xxxx.xxxx:xxxx/xxxx;AuthMech=3;UID=UserName;PWD=Password')

发现行不通

搜索后,总结出如下两种方法:

  1. 使用sqlalchemy与impyla
import sqlalchemy
from impala.dbapi import connect
def conn():
    return connect(host='xxxx.xxxx.xxxx.xxxx', 
                             port=xxxx,
                             database='xxxx',
                             user='xxxx', password='xxxx',
                             auth_mechanism='PLAIN')
engine = sqlalchemy.create_engine('impala://', creator=conn)
  1. 仅使用impyla
from impala.dbapi import connect
conn = connect(host='xxxx.xxxx.xxxx.xxxx', port=xxxx, database='xxxx', user='xxxx', password='xxxx', auth_mechanism='PLAIN')
cursor = conn.cursor()
cursor.execute('show databases')
results = cursor.fetchall()
df = pd.read_sql("SELECT * FROM xxxx", conn)

你可能感兴趣的:(Python,后端,工具)