cx_Oracle.DatabaseError:ORA-12170:TNS:发生连接超时

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

我正在

cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred error while connecting oracle from python.

我已经安装了python 3.7.0和instantclient_11_2。

以下是我正在做的过程,

import cx_Oracle
dsn_tns = cx_Oracle.makedsn( '<ip>', 1521, service_name = '<given service name>')

connection = cx_Oracle.connect('user', 'pwd', dsn_tns) 

我已将系统设置为可验证

PATH
,其中
oci.dll
存在。

可能出了什么问题?

python-3.x oracle cx-oracle instantclient
2个回答
0
投票

尝试:

connection = cx_Oracle.connect('user', 'pwd', cx_Oracle.makedsn( '<ip>', '1521',None,'<given service name>')) 

看起来一样,但在我的 ubuntu 服务器上工作不同。

还要确保将端口放在“ ”之间


0
投票

如果数据库驻留在同一台计算机上,您还应该能够使用以下连接字符串:

connection = cx_Oracle.connect('user/pwd@localhost/service_name')

请注意,service_name 值是必需的。不能使用空字符串!

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