參考 zfno11:& https://ask.hellobi.com/blog/ysfyb/18251
HiveServer是一種可選服務,允許遠程客戶端可以使用各種編程語言向Hive提交請求並檢索結果。
使用Impala 連接hive
安裝前需把相關的包卸載干凈,然后重新安裝對應的版本
pip3 uninstall sasl #運行時報錯module 'sasl' has no attribute 'Client',說明該包沒有刪除干凈,需要手動刪除文件 pip3 install impyla pip3 install pure-sasl pip3 install thrift_sasl==0.2.1 --no-deps
連接代碼:
from impala.dbapi import connect conn = connect(host="xxx.xxx.xx.xxx", port=10000, user="root", auth_mechanism="PLAIN", password='dfghjkl', database="xxx") cur=conn.cursor() cur.execute('SHOW TABLES') for result in cur.fetchall(): print(result)
報錯:TypeError: can't concat str to bytes 需要在File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-p
ackages\thrift_sasl\__init__.py"第94行代碼
修改源代碼:
def _send_message(self, status, body): header = struct.pack(">BI", status, len(body)) self._trans.write(header + body) self._trans.flush()
改為:
def _send_message(self, status, body): header = struct.pack(">BI", status, len(body)) if(type(body) is str): body = body.encode() self._trans.write(header + body) self._trans.flush()
修改之后就OK了。