1

我无法使用 Flask 和 SQLAlchemy 连接到 Hive 数据库。下面查看我在特定文件中的配置:

.flaskenv文件

DATABASE_URL="hive://<host>:10000/<db_name>"

config.py文件

class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
    SQLALCHEMY_ENGINE_OPTIONS = {connect_args={'auth': 'KERBEROS', 'kerberos_service_name': 'hive'}}

数据库.py文件

import os
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

db = SQLAlchemy()
migrate = Migrate()


def register_db(app):
    db.init_app(app)
    migrate.init_app(app, db)

    app.db = db

但是,当我尝试使用flask db run运行应用程序或尝试使用 commnad flask db migrate创建迁移脚本时,我收到错误 [1] -> 似乎连接参数未正确发送到引擎中。

[1]

...
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 2263, in connect
    return self._connection_cls(self, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 104, in __init__
    else engine.raw_connection()
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 2370, in raw_connection
    self.pool.unique_connection, _connection
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 2336, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 304, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 778, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 495, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/impl.py", line 241, in _do_get
    return self._create_connection()
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 440, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 661, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    with_traceback=exc_tb,
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/pool/base.py", line 656, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/default.py", line 493, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.6/dist-packages/pyhive/hive.py", line 94, in connect
    return Connection(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pyhive/hive.py", line 192, in __init__
    self._transport.open()
  File "/usr/local/lib/python3.6/dist-packages/thrift_sasl/__init__.py", line 96, in open
    message=("Bad status: %d (%s)" % (status, payload)))
thrift.transport.TTransport.TTransportException: Bad status: 3 (b'Unsupported mechanism type PLAIN')

Python 包版本:

alembic==1.4.3
Flask==1.1.2
Flask-Migrate==2.5.3
Flask-RESTful==0.3.8
Flask-SQLAlchemy==2.4.4
PyHive==0.6.2
python-dotenv==0.15.0
sasl==0.2.1
SQLAlchemy==1.3.20
ssh-import-id==5.7
thrift==0.13.0
thrift-sasl==0.4.2

有人可以帮我吗?

4

0 回答 0