从Azure Databricks访问Azure容器失败:$root容器未找到求助
问题:Azure Databricks挂载Azure存储容器时提示找不到$root容器
我按步骤创建容器并生成SAS令牌,在Databricks笔记本执行挂载命令时出现异常,提示找不到$root容器,但已确认目标存储账户和容器均存在。
执行的代码
变量定义
container_name = "containertobesharedwithdatabricks" storage_account_name = "atabricksstorageaccount" storage_account_url = storage_account_name + ".blob.core.windows.net" sas = "?sv=2021-06-08&ss=bfqt&srt=o&sp=rwdlacupiytfx&se=..."
挂载参数构建
endpoint_source = "wasbs://"+ storage_account_url + "/" + container_name mountPoint_folder = "/mnt/projet8" config = "fs.azure.sas."+ container_name + "."+ storage_account_url
挂载命令
dbutils.fs.mount( source = endpoint_source, mount_point = mountPoint_folder, extra_configs = {config : sas})
报错信息
shaded.databricks.org.apache.hadoop.fs.azure.AzureException: shaded.databricks.org.apache.hadoop.fs.azure.AzureException: Container $root in account atabricksstorageaccount.blob.core.windows.net not found, and we can't create it using anonymous credentials, and no credentials found for them in the configuration.
确认信息
存储账户与目标容器已存在:
解决方案
问题根源是endpoint_source的格式错误:正确的wasbs协议格式应为wasbs://<容器名>@<存储账户URL>,你当前的写法把存储账户URL放在了容器名前面,导致Databricks误解析路径,进而尝试访问默认的$root容器。
修正后的endpoint_source代码:
endpoint_source = f"wasbs://{container_name}@{storage_account_url}"
额外注意事项
- 确保SAS令牌拥有容器的读写等必要权限,且处于有效期内
- 若挂载路径
/mnt/projet8已存在,需先执行卸载命令:
dbutils.fs.unmount("/mnt/projet8")
再重新执行挂载操作
内容的提问来源于stack exchange,提问作者p-y
相关产品推荐
相关产品推荐

