You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQLAlchemy+OracleDB连接Oracle数据库遇DPY-6005/DPY-3008错误

Python SQLAlchemy 结合 OracleDB 连接数据库报错求助

我用Python的SQLAlchemy搭配OracleDB连接Oracle数据库时,一直报以下错误:

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

用相同的认证信息可以正常通过DBeaver和Pentaho连接,因此排除防火墙等网络问题。我的代码如下:

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)

我尝试了三种连接字符串写法,对应的错误如下:

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

报错:

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)
  • 写法2(使用完整DSN):
oracle_engine = create_engine(f'oracle+oracledb://{oracle_user}:{oracle_password}@{dsn_oracle}')

仍出现最初的DPY-6005/DPY-3008错误,寻求解决办法。

内容的提问来源于stack exchange,提问作者mrlelis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 08:42:08