【问题标题】:cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurredcx_Oracle.DatabaseError:ORA-12170:TNS:发生连接超时
【发布时间】:2019-01-21 01:01:05
【问题描述】:

我来了

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


    【解决方案1】:

    试试:

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

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

    还要确保将端口放在''之间

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2019-11-13
        • 2020-10-10
        • 2014-07-21
        • 2016-12-04
        • 1970-01-01
        • 2015-11-03
        • 2012-02-03
        • 2016-07-29
        • 2015-05-23
        相关资源
        最近更新 更多