Home > OS >  What does 'ConnectionRefusedError: [Errno 61] Connection refused' mean with python-oracled
What does 'ConnectionRefusedError: [Errno 61] Connection refused' mean with python-oracled

Time:05-26

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:

ConnectionRefusedError: [Errno 61] Connection refused

on Linux the error is like:

ConnectionRefusedError: [Errno 111] Connection refused

What do these mean?

CodePudding user response:

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.

CodePudding user response:

In my experience, "connection refused" often means that the connection was actively denied, which could mean that the database is protected by a firewall. If you have already confirmed the hostname and port are correct and are still getting this error then determine if there is a firewall, either on the database server itself or elsewhere on the network, and have a rule created to allow access or disable it entirely (assuming it is safe to do so).

  • Related