问题
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
回答1:
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.
回答2:
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)
回答3:
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.
来源:https://stackoverflow.com/questions/15772351/ocx-oracle-ora-12541-tns-no-listener