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

Airflow环境下python-oracledb连接Oracle12.1报错DPY-3011如何解决?

DPY-3011错误解析与解决方法

错误含义

DPY-3011: server logon version is not supported 是python-oracledb抛出的兼容性错误,说明当前使用的python-oracledb版本不支持连接Oracle 12.1数据库。python-oracledb 2.0及以上版本默认的Thin模式(无需Oracle客户端)不再对Oracle 12.1提供支持,这也是你连接19c正常但12.1报错的核心原因。

解决方法

1. 降级python-oracledb到兼容版本

python-oracledb 1.4.x系列仍保留对Oracle 12.1的支持,执行以下命令安装指定稳定版本:

pip install python-oracledb==1.4.2

注意:Airflow环境中需确保该安装操作在Worker或Scheduler的依赖环境中执行,避免干扰其他任务的依赖配置。

2. 使用python-oracledb的Thick模式

即使使用新版本python-oracledb,切换到Thick模式(依赖Oracle Instant Client)可兼容Oracle 12.1:

  • 下载适配系统的Oracle Instant Client(推荐19c版本,可向下兼容12.1)
  • 在Airflow任务代码中初始化Thick模式:
    import oracledb
    
    # 替换为你的Oracle Instant Client实际路径
    oracledb.init_oracle_client(lib_dir="/opt/oracle/instantclient_19_19")
    
    # 建立数据库连接
    connection = oracledb.connect(
        user="你的用户名",
        password="你的密码",
        dsn="你的Oracle数据库DSN"
    )
    
  • Linux环境需确保Airflow进程能读取LD_LIBRARY_PATH环境变量(指向Instant Client目录);Windows环境需将Instant Client路径加入系统PATH。

3. 升级Oracle数据库(可选)

如果业务场景允许,将Oracle 12.1升级到12.2及以上版本,即可直接使用新版本python-oracledb的默认Thin模式连接,无需额外配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 11:36:18