使用 Python 和 cx_oracle 连接到 Oracle 数据库

Connecting to Oracle Database Using Python with cx_oracle

我正在使用 cx_oracle 连接 Oracle 数据库,使用 python.I 需要您帮助连接数据库。到目前为止,我一直在使用以下代码,它运行良好

代码-1:

import cx_Oracle as cx
dsn_tns = cx.makedsn(HOST,PORT, service_name=SERVICE_NAME)
conn = cx.connect(user=USER, password=PW, dsn=dsn_tns)

最近 TCP 端口被禁用,我们正在使用 jdbc 连接字符串连接具有 TCPS 端口的数据库 number.can 你帮助我需要通过上面的协议/建议任何其他方法。

我尝试了以下代码

code-2:

dsn_tns='(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = tcps)(HOST =hostdetails)(PORT =port))) (CONNECT_DATA = (SERVICE_NAME = servicename)))'
conn = cx.connect(user=USER, password=PW, dsn=dsn_tns)
print(cx.version)

我得到了error: ORA-28759: failure to open file

如有任何建议,我们将不胜感激。提前谢谢你。

你的 sqlnet.ora 有定义 WALLET_LOCATION 吗?

Source.