Search code examples
pythonpython-3.xoraclesqlalchemypython-oracledb

Python-oracledb: DPY-6005: cannot connect to database (CONNECTION_ID=""). DPY-3008: unsupported in-band notification with error number 12572


I'm trying to connect to an Oracle database in Python using SQLAlchemy together with OracleDB. But I always get this error:

sqlalchemy.exc.OperationalError: (oracledb.exceptions.OperationalError) DPY-6005: cannot connect to database (CONNECTION_ID=1f27PvoJ7yfyC1G5UcfdNQ==).
DPY-3008: unsupported in-band notification with error number 12572

I can connect to the database using the same authentication with DBeaver and Pentaho, so I don't think the problem here is firewall or something like that.

The code is very simple:

import pandas as pd
import oracledb
from sqlalchemy import create_engine
from os.path import realpath, dirname

# Script path
path = realpath(dirname(__file__))

oracle_user = 'secret'
oracle_password = 'secret'
oracle_host = 'secret'
oracle_port = 'secret'
oracle_service_name = 'secret'
dsn_oracle = '''(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SECRET)(PORT=1521))
            (CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=SECRET)))'''

oracle_engine = create_engine(f'oracle+oracledb://{oracle_user}:{oracle_password}@{oracle_host}:{oracle_port}/?service_name={oracle_service_name}')
df = pd.read_sql('SELECT * FROM SILOMS.T_TIPO_DISPONIBILIDADE', oracle_engine)

I've tried the following changes:

  • oracle_engine = create_engine(f'oracle+oracledb://{oracle_user}:{oracle_password}@{oracle_host}:{oracle_port}/{oracle_service_name}')

The code above gets a different error:

DPY-6005: cannot connect to database (CONNECTION_ID=Ahugep/3dI6/h82DqaM/BA==).
DPY-6003: SID "SECRET_SERVICE_NAME" is not registered with the listener at host "SECRET_HOST_NAME" port 1521. (Similar to ORA-12505)
  • oracle_engine = create_engine(f'oracle+oracledb://{oracle_user}:{oracle_password}@{dsn_oracle}')

The code above gets the same 12572 error (DPY-3008) from the title


Solution

  • This has been repaired in version 2.4.1 which was released yesterday (August 22, 2024).