cx_Oracle.DatabaseError: ORA-12170: TNS:Connect timeout occurred

依然范特西╮ 提交于 2021-01-28 11:11:53

问题


I am getting

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

I have installed python 3.7.0 and instantclient_11_2.

Below are the process i am doing,

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

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

I have set system veriable PATH where oci.dll is present.

What could be wrong?


回答1:


Try:

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

Looks the same but works different in my ubuntu server.

Also make sure to put the port between ' '




回答2:


You should also be able to use the following connect string if the database resides on the same machine:

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

Note that a service_name value is required. You can't use the empty string!



来源:https://stackoverflow.com/questions/51836874/cx-oracle-databaseerror-ora-12170-tnsconnect-timeout-occurred

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!