Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'DPY-6005: cannot connect to database. Connection failed with "[Errno 61] Connection refused"' mean with python-oracledb

On macOS with Python 3.9.6 the Python code using Oracle's python-oracledb driver:

import oracledb
import os

un = os.environ.get("PYTHON_USERNAME")
pw = os.environ.get("PYTHON_PASSWORD")
cs = "localhost/orclpdb1"

c = oracledb.connect(user=un, password=pw, dsn=cs)

gives the error:

DPY-6005: cannot connect to database. Connection failed with "[Errno 61] Connection refused"

on Linux the error is like:

DPY-6005: cannot connect to database. Connection failed with "[Errno 111] Connection refused"

What do these mean?

[Update: in python-oracledb 1.0.1 the error is wrapped with DPY-6005. In 1.0.0 just the lower level Python part of the error was shown.]

like image 507
Christopher Jones Avatar asked Dec 30 '25 19:12

Christopher Jones


1 Answers

  • One scenario is that the database port you used (or the default port 1521) is not correct. Find the correct port and use that instead. For example if your database listener is listening on port 1530 instead of the default port 1521, then you could try the connection string:

    cs = "localhost:1530/orclpdb1"
    
  • Make sure the hostname is correct: you may have connected to the wrong machine.

like image 107
Christopher Jones Avatar answered Jan 01 '26 11:01

Christopher Jones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!