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

Python读取Azure私有DataLake Storage中CSV文件失败求助

问题1:Azure SDK下载文件时连接失败

报错信息:"Failed to establish a new connection: [Errno -2] Name or service not known"

解决思路

  • DNS解析异常:能列出文件说明权限和基本连接没问题,但下载时DNS解析失败。可以通过ping {storage_account_name}.dfs.core.windows.net获取存储账户IP,手动在本地hosts文件绑定;或者切换网络环境(比如从内网换为公网)测试。
  • 端点格式校验:确认account_url严格为https://{storage_account_name}.dfs.core.windows.net,无拼写错误或多余字符。
  • 代理/防火墙限制:如果网络存在代理或防火墙,需配置SDK的代理参数:
    from azure.storage.filedatalake import DataLakeServiceClient
    from azure.core.pipeline.transport import RequestsTransport
    
    transport = RequestsTransport(proxies={"https": "http://你的代理地址:端口"})
    service_client = DataLakeServiceClient(
        account_url=f"https://{storage_account_name}.dfs.core.windows.net",
        credential=storage_account_key,
        transport=transport
    )
    
  • SDK版本更新:升级Azure存储SDK到最新版本:
    pip install --upgrade azure-storage-file-datalake
    

问题2:Pandas使用abfs路径读取时报错

报错信息:"storage_options passed with file object or non-fsspec file path"

解决思路

这个错误是因为Pandas无法识别abfs[s]路径格式,需依赖fsspec和adlfs包实现文件系统适配:

  1. 先安装依赖包:
    pip install fsspec adlfs
    
  2. 修改路径格式(无需转义[]),且路径需指向具体CSV文件:
    import pandas as pd
    
    # 使用加密的abfss协议(推荐)
    df = pd.read_csv(
        f'abfss://{container_name}/{file_path}/Test_DataQuality.csv',
        storage_options={'account_key': storage_account_key}
    )
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 09:10:22