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包实现文件系统适配:
- 先安装依赖包:
pip install fsspec adlfs - 修改路径格式(无需转义
[]),且路径需指向具体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
相关产品推荐
相关产品推荐

