【问题标题】:Can't access mounted volume with python on Databricks无法在 Databricks 上使用 python 访问已安装的卷
【发布时间】:2020-05-01 01:27:35
【问题描述】:

我正在尝试通过使用凭据直通将 Azure 存储帐户 Gen2 容器安装到 dbfs 来向他们的 Databricks 工作区中的团队授予对 Azure 存储帐户 Gen2 容器的访问权限。我希望能够使用 Active Directory 管理访问,因为最终会有容器以只读方式挂载。

我的代码基于本教程:https://docs.microsoft.com/en-us/azure/databricks/data/data-sources/azure/adls-passthrough#adls-aad-credentials

从我的 conf 中提取:

"spark_conf": {
        "spark.databricks.cluster.profile": "serverless",
        "spark.databricks.passthrough.enabled": "true",
        "spark.databricks.delta.preview.enabled": "true",
        "spark.databricks.pyspark.enableProcessIsolation": "true",
        "spark.databricks.repl.allowedLanguages": "python,sql"
    }

然后我运行以下代码:

dbutils.fs.mount(
  source = f"wasbs://data@storage_account_name.blob.core.windows.net",
  mount_point = "/mnt/data/",
  extra_configs = {
  "fs.azure.account.auth.type":"CustomAccessToken",
  "fs.azure.account.custom.token.provider.class":spark.conf.get("spark.databricks.passthrough.adls.gen2.tokenProviderClassName")
}

这是成功的,因为我可以使用 dbutils 访问该卷。

>> dbutils.fs.ls('dbfs:/mnt/storage_account_name/data')
[FileInfo(path='dbfs:/mnt/storage_account_name/data/folder/', name='folder/', size=0)]

我的问题是当我运行 %sh ls /dbfs/mnt/storage_account_name/data 或尝试使用 python 访问它时

>> import os 
>> os.listdir('/dbfs/')
Out[1]: []

>> os.listdir('/dbfs/mnt/')
FileNotFoundError: [Errno 2] No such file or directory: '/dbfs/mnt/'

我找不到我错过了什么。是否需要配置一些东西以使其可供 python 访问? 谢谢。

【问题讨论】:

    标签: python pyspark databricks azure-databricks azure-storage-account


    【解决方案1】:

    当您使用凭证直通选项时存在某些限制,这就是它不起作用的原因。不存在语法问题。看这个offical doc就明白了。

    【讨论】:

      【解决方案2】:

      答案很简单。

      本地文件 API 限制

      以下列表列举了本地文件 API 使用的限制 适用于每个 Databricks 运行时版本。

      All - Does not support credential passthrough.
      

      来源:https://docs.microsoft.com/en-us/azure/databricks/data/databricks-file-system#local-file-apis

      【讨论】:

        猜你喜欢
        • 2021-01-12
        • 2021-11-26
        • 2020-07-30
        • 2020-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多