通过Pysimplegui从Python(3.9.7)与Hive连接

发布于 2025-02-08 13:42:28 字数 1515 浏览 2 评论 0原文

我正在尝试从Python(脚本)连接到Hive,并且连接成功。但是,当我通过创建的GUI传递相同的CONN STR详细信息时,我会发现错误:

gaierror:[Errno 8] NodeName nor servName提供了或不知道哪些导致TransportException:ttransportException(type = 1,message = 1,message =“无法连接到主机,端口,auth_mech,auth_mech,kerb_serv_name,timeout,timeout,timeout,use_ssl”)。<<<<<<)。 /p>

当值直接传递而不是下面的conn str时,上述执行正常:

import pandas as pd
import PySimpleGUI as sg
from impala.dbapi import connect
from impala.util import as_pandas

layout_h = [
    [sg.Text('host',size=(10,1)),sg.Input(key='h')],
    [sg.Text('port',size=(10,1)),sg.Input(key='p')],
    [sg.Text('auth_mechanism',size=(10,1)),sg.Input(key='am')],
    [sg.Text('kerberos_service_name',size=(10,1)),sg.Input(key='ksn')],
    [sg.Text('timeout',size=(10,1)),sg.Input(key='t')],
    [sg.Text('use_ssl(True/False)',size=(10,1)),sg.Input(key='ssl')],
    [sg.Button('Test Connection'),sg.Button('Quit')],
    [sg.Text('Enter SQL',size=(10,1)),sg.Input(key='sqlquery1')],
    [sg.Button('Profile and Save'),sg.Button('Exit')]
]
sg.theme('dark grey 6')
window = sg.Window('Hive',layout_h)
event,values = window.read()
if event == 'Test Connection':
    hiv = connect(str(values['h'])+","+values['p']+","+str(values['am'])+","+str(values['ksn'])+","+values['t']+","+values['ssl'])

    imp_cursor = hiv.cursor()
    imp_cursor.execute(values['sqlquery1'])
    AV = as_pandas(imp_cursor)

ps我想我弄乱了conn str(noobie试图自动化他的任务)

I am trying to connect to hive from python (script) and the connection is successful. However when I am passing the same conn str details via a GUI i created, I get the error :

gaierror: [Errno 8] nodename nor servname provided, or not known which leads to TTransportException: TTransportException(type=1, message="Could not connect to host,port,auth_mech,kerb_serv_name,timeout,use_ssl").

The above executes fine when the values are passed directly instead of the conn str below:

import pandas as pd
import PySimpleGUI as sg
from impala.dbapi import connect
from impala.util import as_pandas

layout_h = [
    [sg.Text('host',size=(10,1)),sg.Input(key='h')],
    [sg.Text('port',size=(10,1)),sg.Input(key='p')],
    [sg.Text('auth_mechanism',size=(10,1)),sg.Input(key='am')],
    [sg.Text('kerberos_service_name',size=(10,1)),sg.Input(key='ksn')],
    [sg.Text('timeout',size=(10,1)),sg.Input(key='t')],
    [sg.Text('use_ssl(True/False)',size=(10,1)),sg.Input(key='ssl')],
    [sg.Button('Test Connection'),sg.Button('Quit')],
    [sg.Text('Enter SQL',size=(10,1)),sg.Input(key='sqlquery1')],
    [sg.Button('Profile and Save'),sg.Button('Exit')]
]
sg.theme('dark grey 6')
window = sg.Window('Hive',layout_h)
event,values = window.read()
if event == 'Test Connection':
    hiv = connect(str(values['h'])+","+values['p']+","+str(values['am'])+","+str(values['ksn'])+","+values['t']+","+values['ssl'])

    imp_cursor = hiv.cursor()
    imp_cursor.execute(values['sqlquery1'])
    AV = as_pandas(imp_cursor)

P.S. I think I messed up the conn str(noobie trying to automate his tasks)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文