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.]
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:
Make sure the hostname is correct: you may have connected to the wrong machine.