如何使用 Docker 将 Apache Superset 与 Oracle 连接

问题描述 投票:0回答:1

我在我的 python Docker 容器中安装了

cx_oracle
。连接到 Oracle 数据库时出现此错误:

An error occurred while creating databases: (builtins.NoneType) None
[SQL: (cx_Oracle.DatabaseError) DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
(Background on this error at: https://sqlalche.me/e/14/4xp6)]
(Background on this error at: https://sqlalche.me/e/14/dbapi)

使用 Docker 连接 Oracle 数据库并在 docker 终端执行 python Oracle 连接代码:

import cx_Oracle

connection = cx_Oracle.connect('admin/[email protected]:1521/DATABASE')
cur = connection.cursor()

enter image description here

dockerfile cx-oracle apache-superset python-oracledb
1个回答
1
投票

根据您的错误消息,您可能缺少 Oracle 客户端库 Oracle Instant Client。 新的主要 Python cx_Oracle 驱动程序版本可作为

python-oracledb
获得,并且不需要 Oracle 客户端库。

安装和使用 python-oracledb:

python -m pip install oracledb

使用以下方法测试与 Oracle 的连接:

import oracledb
    
connection = oracledb.connect(user='scott', password=secretpw, dsn='localhost/oraclepdb1')
    
with connection.cursor() as cursor:
  for row in cursor.execute('select * from dual'):
    print(row)

更多信息请参见:将 Oracle Instant 客户端安装到 Python cx_Oracle 的 Docker 容器中

© www.soinside.com 2019 - 2024. All rights reserved.