【问题标题】:username & password with presto-python-clientpresto-python-client 的用户名和密码
【发布时间】:2020-10-14 20:18:01
【问题描述】:

我正在尝试替换 jaydebeapi 与 facebook 的 presto-python-client 问题是如何替换认证位

db = jaydebeapi.connect(connection['jclass'], connection['host'],[ connection['user'], connection['pass']], connection['jar'])

使用 presto-python-client 时

import prestodb
conn= prestodb.dbapi.connect(
    host='localhost',
    port=8080,
    user='the-user',
    catalog='the-catalog',
    schema='the-schema',
    isolation_level=transaction.IsolationLevel.REPEATABLE_READ,
)

我找不到任何地方指定如何传递密码。 此更改的原因是我在尝试使用 jaydebeapi 传递长查询(18k 个字符)时遇到模棱两可的错误

【问题讨论】:

  • 你找到答案了吗?
  • @CristhianBoujon 抱歉,现在才看到您的评论 :) 我们最终使用了 SQLAlchemy,因此解决方案来自 sqlalchemy.engine import create_engine engine = create_engine('presto://{0}:{1} @{2}:{3}/hive'.format(connection['user'],connection['pass'],connection['host'],int(connection['port'])), connect_args={'协议': 'https', 'requests_kwargs': {'verify': False}}) db = engine.raw_connection()

标签: python-2.7 presto


【解决方案1】:

我们最终使用了 SQLAlchemy,所以解决方案是

from sqlalchemy.engine import create_engine 
engine = create_engine('presto://{0}:{1}@{2}:{3}/hive'.format(connection['user'],connection['pass'],connection['host'],int(connection['port'])), connect_args={'protocol': 'https', 'requests_kwargs': {'verify': False}}) 
db = engine.raw_connection()

【讨论】:

  • 我收到了NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:presto。您使用的是什么安装的 sqlalchemy?
  • @DimaLituiev 根据文档docs.sqlalchemy.org/en/14/dialects,您还应该安装 PyHive
【解决方案2】:

现在旧方法已弃用,所以这里是连接到 presto 的新方法

cursor = presto.connect(presto_host,
                                presto_port,
                                requests_kwargs={'auth': HTTPBasicAuth(presto_username, presto_password)},
                                poll_interval=1,
                                protocol='https',
                                source='pyhive').cursor()

【讨论】:

    猜你喜欢
    • 2011-05-27
    • 2021-07-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    相关资源
    最近更新 更多