使用azure.storage.filedatalake import DataLakeServiceClient
在 Python 中,我创建了将文件上传到 Azure datalake gen 2 的功能。这可以正常工作,因为我上传的文件确实显示在我的 Datalake 中,无论是在本地运行我的代码还是使用我的 azurewebsite.net 时。
我现在正在尝试创建可以在我的 Datalake 中创建新容器/文件系统的功能,然后我可以将文件上传到其中。这在本地有效,但是当我在我的 azure 网站上尝试执行此操作时,出现以下错误:
HttpResponseError /project/create_file_container/
This request is not authorized to perform this operation.
ErrorCode: AuthorizationFailiure
我可以看到代码在这个特定点失败:
service_client = settings.SERVICE_CLIENT
# Creates a new datalake file_system for the org
system_name = 'org-1'
service_client.create_file_system(file_system=system_name) #<-- Fails on this line
我的service_client定义为:
STORAGE_ACCOUNT_NAME = 'my_datalake'
STORAGE_ACCOUNT_KEY = 'my account key'
global SERVICE_CLIENT
SERVICE_CLIENT = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format(
"https", STORAGE_ACCOUNT_NAME), credential=STORAGE_ACCOUNT_KEY)
创建 file_systems 时是否必须提供一些额外的身份验证?我认为由于我可以上传文件,因此也允许创建 file_systems。
最佳答案
我也遇到过同样的问题,这是一个权限问题。确保为服务主体分配 Data Lake Storage Gen2 存储帐户范围内的 Blob 存储贡献者角色。
注意:您可以将角色分配给父级订阅或资源组,但将其分散到存储帐户将需要时间进行分配。如果将订阅或资源分配给订阅或资源组,然后建立存储帐户,则应立即继承该任务。当您完成类(class)时,您应该将您的帐户直接附加到存储帐户,这样它就不会被阻止,并且如果您已经使用了存储帐户,则不必等待。
关于python - 为什么我无权使用 Python 在 Data Lake gen2 中创建文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68653524/