0

I am trying to connect to a remote Oracle database using Python. I am able to access the database directly using DBeaver and I have copied the parameters in the Python code below from the "Connection Configuration --> Connection settings --> General" tab (which can be opened by right-clicking on the database and selecting "Edit connection"):

import cx_Oracle

host_name   = # content of "Host"
port_number = # content of "Port"
user_name   = # content of "User name"
pwd         = # content of "Password"
service_name = # content of "Database" (the "Service Name" option is selected)

dsn_tns = cx_Oracle.makedsn(host_name, port_number, service_name = service_name)
conn = cx_Oracle.connect(user = user_name, password = pwd, dsn = dsn_tns)

However, I get the following error:

DatabaseError: ORA-12541: TNS:no listener

Other answers I found related to this question suggested modifying some values inside the listener.ora file, but I have no such file on my computer nor do I know where it can be retrieved. Does anyone have any suggestions?

1 Answer 1

2

There would be two reason for that error.

  • The database was briefly unavailable at the time when you tried to access
  • The Oracle client application on your machine is not configured correctly

I think thi config is not correct. See the link : https://oracle.github.io/python-cx_Oracle/

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

db = cx_Oracle.connect('username', 'password', dsn_tns) 
Sign up to request clarification or add additional context in comments.

1 Comment

Most users are not using (the very, very old) SIDs for connection but are using Service Names, so the syntax would be: dsn_tns = cx_Oracle.makedsn("dbhost.example.com", 1521, service_name="orclpdb1"), see the doc at cx-oracle.readthedocs.io/en/latest/user_guide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.