【问题标题】:how to specify https protcol in SQLAlchemy > Presto connection?如何在 SQLAlchemy > Presto 连接中指定 https 协议?
【发布时间】:2020-12-23 23:58:01
【问题描述】:

我正在尝试使用 SQLAlchemy 通过 Presto 运行 Hive 查询。它使用 LDAP 身份验证,但我在连接字符串中遗漏了一些内容。

from sqlalchemy.engine import create_engine

conn_string = 'presto://' + user + ':' + passw + '@' + host + ':' + port + db \
    + ", connect_args={'auth':LDAP}"
   
eng = create_engine(conn_string)

我收到一条错误消息:

Protocol must be https when passing a password

我在搜索时看到了一些关于此的讨论,但没有看到明确的解决方案。我已经尝试了很多有或没有端口、数据库等的组合。你知道怎么做吗?谢谢!

【问题讨论】:

    标签: sql python-3.x hive sqlalchemy presto


    【解决方案1】:

    我最终使用了另一个有效的库:

    import prestodb
    
    conn=prestodb.dbapi.connect(
        host=host,
        port=port,
        user=user,
        catalog='db_name',
        schema='my_schema',
        http_scheme='https',
        auth=prestodb.auth.BasicAuthentication(user, passw)
    )
    

    然后我能够检索结果并将其放入数据框中。所以不需要 SQLAlchemy。这似乎是不必要的复杂。

    【讨论】:

      【解决方案2】:

      README of PyHive 包含这个 sn-p:

      create_engine(
          'presto://user@host:443/hive',
          connect_args={'protocol': 'https',
                        'session_props': {'query_max_run_time': '1234m'}}
      )
      

      看来您需要做的只是将'protocol': 'https' 添加到connect_args。

      【讨论】:

      • 我只是注意到在那个例子中他们没有指定密码。不知道那是如何工作的。无论如何,我确实喜欢那样,现在我得到“连接尝试失败,因为连接方在一段时间后没有正确响应”,
      【解决方案3】:

      从 sqlalchemy.engine 导入 create_engine engine = create_engine('presto://username:password@vmwidpappprd.corp.net.com:8443/hive', connect_args={'protocol': 'https', 'requests_kwargs': {'verify': False}}) db = engine.raw_connection() s=engine.execute("SELECT * FROM idp_dim_prd.sales_territory") 印刷) 对于 s 中的 r: 打印(r)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-31
        相关资源
        最近更新 更多