简体   繁体   中英

Connecting to remote Oracle database using Python

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?

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM