ocx_Oracle ORA-12541 tns no listener
Asked Answered
O

3

8

I try to connect to a remote oracle server by cx_Oracle:

db = cx_Oracle.connect('username', 'password', dsn_tns)

but it says databaseError: ORA-12541 tns no listener

Onomatology answered 2/4, 2013 at 19:10 Comment(0)
D
6

I was able to connect via db client (e.g datagrip), but I got the No Listener error when i connect from python script because my original connection string did not specify the port. I was following the cx_Oracle doc

This post helped me by specifying the port this way:

ip = '192.168.0.1'
port = 1521
SID = 'YOURSIDHERE'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)

db = cx_Oracle.connect('username', 'password', dsn_tns)
Defrost answered 9/2, 2018 at 3:13 Comment(2)
thank you, that was really helpful. making a dsn in this way solved my problem.During
Thanks! makedsn() also accepts service_name='foo' instead of an SID, which is what I needed. cx-oracle.readthedocs.io/en/6.4/module.html#cx_Oracle.makedsnDingus
F
2

This error may occur if the listener.ora file (on the Oracle server itself) is configured to listen for "localhost" instead of the machine name.

LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = WN700014)(PORT = 1521)) ) )

See this post.

Floridafloridia answered 15/8, 2013 at 13:15 Comment(0)
W
1

In my case it was due to the fact that my server port was wrong:

./install_database_new.sh localhost:1511 XE full

I changed the port to "1521" and I could connect.

Witchhunt answered 13/10, 2017 at 10:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.