问题
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