Cx 甲骨文 'TNS could not resolve the connect identifier'

Cx Oracle 'TNS could not resolve the connect identifier'

我正在使用 LDAP 和 Python cx_Oracle 库连接到 Oracle 数据库。我有适当的 sqlnet.ora、ldap.ora 和 tnsnames.ora 文件。在我的 Windows 机器上,使用 12.1 Oracle 客户端和以下 Python 代码一切正常:

import cx_Oracle
connection = cx_Oracle.connect(user/password@db, mode=cx_Oracle.SYSDBA)

我已经按照 Oracle 网站(https://www.oracle.com/be/database/technologies/instant-client/linux-x86-64-downloads.html 底部)建议的 zip 文件安装方法在我的 Linux 机器 (Debian) 上安装了 Oracle 即时客户端 12.1。 ldconfig 正确列出了 oracle 客户端库及其路径。

我将完全相同的 sqlnet.ora、ldap.ora 和 tnsnames.ora 文件从我的 Windows 机器复制到我的 Linux 机器 在 /opt/oracle/instantclient_12_1/network/admin 中,根据 cx_Oracle 文档的建议。

现在 运行 我的 Linux 机器上的上述 Python 代码出现以下错误:

cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

我也试过设置环境变量 TNS_ADMIN=/opt/oracle/instantclient_12_1/network/adminORACLE_HOME=/opt/oracle/instantclient_12_1/ 都没有成功

你们谁能帮我调试这个并理解为什么我的 Linux 机器上的客户端配置不起作用?

安装了最新的 19 客户端,一切正常。