1

我正进入(状态

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

有什么问题?

4

2 回答 2

0

尝试:

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

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

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

于 2018-08-14T19:55:16.183 回答
0

如果数据库位于同一台机器上,您还应该能够使用以下连接字符串:

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

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

于 2018-08-14T21:14:41.717 回答