使用 python 的 Oracle 数据库连接不工作

Oracle database connection using python is not Working

我正在尝试使用 cx_Oracle 连接到 python 中的 oracle 数据库。但是我遇到了以下错误。

参考我的代码

  def runQuery(self,query):
        with cx_Oracle.connect(config.username,config.password,config.dsn,encoding=config.encoding) as connection:
            try:
                print(connection.version)
            except cx_Oracle.Error as error:
                print(error)

配置文件

username = 'dummy'
password = 'dummy'
dsn = 'dummy@//localhost:1521/ORCLCDB.localdomain'
port = 1512
encoding = 'UTF-8'

为了获得更多知识,为此目的使用 oracle 数据库的 docker 图像。

我可以知道如何解决问题并继续进行吗?有人可以帮助找出我的实现中缺少的内容吗?

您是否安装了 Oracle Instant Client?看起来您正在使用 Ubuntu。对于基于 RPM 的发行版,安装将 look like this. There are instructions out there to install Oracle Instant Client on Ubuntu as well, but perhaps you are better of putting your Python code and cx_Oracle in a container as well, as Chris Jones explains here.