如何向azureml.fsspec.AzureMachineLearningFileSystem传递数据存储URI?
问题:AzureML数据存储URI格式错误导致ValueError
已注册ADLS类型数据存储,执行以下代码时触发格式验证错误:
datastore = mlclient.datastores.get(ds_name)
from azureml.fsspec import AzureMachineLearningFileSystem # 原拼接的URI ds_url = f"azureml://subscriptions/{subscriptionID}/resourcegroups/{RG}/workspaces/{ws_name}/datastore/adls/paths/iris-processed/*" fs = AzureMachineLearningFileSystem(ds_url) fs.ls()
错误信息:
ValueError: azureml://subscriptions/xx/resourcegroups/xx/workspaces/xx/datastore/adls/paths/iris-processed/* is not a valid datastore uri: azureml://subscriptions/([^\/]+)/resourcegroups/([^\/]+)/(?:Microsoft.MachineLearningServices/)?workspaces/([^\/]+)/datastores/([^\/]+)/paths/(.*)
解决方案
核心问题是URI中的**datastore是单数**,但AzureML的规范要求用**datastores(复数)**——错误提示里的正则表达式已经明确标注了这一点(datastores/([^\/]+))。
有两种正确的写法:
1. 手动修正URI格式
把URI里的datastore改成datastores即可:
ds_url = f"azureml://subscriptions/{subscriptionID}/resourcegroups/{RG}/workspaces/{ws_name}/datastores/adls/paths/iris-processed/*" fs = AzureMachineLearningFileSystem(ds_url) fs.ls()
2. 通过datastore对象自动生成正确URI(推荐)
避免手动拼接出错,直接用已获取的datastore对象生成合规的URI:
datastore = mlclient.datastores.get(ds_name) # 生成指定路径的URI,支持通配符 ds_url = datastore.path("iris-processed/*").as_uri() fs = AzureMachineLearningFileSystem(ds_url) fs.ls()
内容的提问来源于stack exchange,提问作者TheHumanSpider
相关产品推荐
相关产品推荐

