2

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?

jalazbe
  • 1,801
  • 3
  • 19
  • 40
techie
  • 21
  • 1
  • 2

2 Answers2

0

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 ' '

jalazbe
  • 1,801
  • 3
  • 19
  • 40
0

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!

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23