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

如何从Airflow连接ID获取Azure Blob Storage连接字符串

提取方法

你可以通过以下代码直接从WasbHook实例中获取对应的Azure连接字符串:

# 获取底层Airflow连接配置对象
conn = azure_conn.get_connection(azure_conn.wasb_conn_id)

# 从连接的额外配置字段中读取预设的连接字符串
azure_conn_str = conn.extra_dejson.get("connection_string")

其他适配场景

  • 如果你不确定连接配置的extra字段存储结构,可以先打印所有额外配置确认字段名:
    print(conn.extra_dejson)
    
  • 如果你是用账户名+访问密钥的方式配置的Wasb连接,没有直接存储连接字符串,可以手动拼接:
    account_name = conn.login
    account_key = conn.password
    azure_conn_str = f"DefaultEndpointsProtocol=https;AccountName={account_name};AccountKey={account_key};EndpointSuffix=core.windows.net"
    

以上方法适用于Airflow 2.x及microsoft azure provider 2.0+版本,旧版本可将extra_dejson替换为extra后自行解析JSON字符串。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 22:39:05