【发布时间】:2021-10-04 06:30:47
【问题描述】:
当我尝试使用函数应用从 blob 存储读取 txt 文件时,它会在日志中返回此错误:
结果:失败异常:HttpResponseError:此请求无权使用此权限执行此操作。 RequestId:00000-0000-00000-00000-000000000000 时间:2021-07-28T13:14:46.7803762Z 错误代码:AuthorizationPermissionMismatch 错误:无
在存储帐户的访问控制菜单中,已将“存储 Blob 数据贡献者”角色分配给函数应用的系统分配标识。
这是我的代码:
import logging
import azure.functions as func
from azure.storage.blob import BlobServiceClient, BlobClient
from azure.identity import DefaultAzureCredential
def main(req: func.HttpRequest) -> func.HttpResponse:
blob_url = "https://my-storage-account.blob.core.windows.net"
blob_credential = DefaultAzureCredential()
blob_client = BlobClient(account_url=blob_url, container_name='tests', blob_name='file.txt', credential=blob_credential)
download_stream = blob_client.download_blob()
logging.info('Contents of the download_stream: %s', download_stream)
return func.HttpResponse("OK", status_code=200)
为什么我得到的是错误而不是 'file.txt' 的内容?
【问题讨论】:
标签: python azure-functions azure-blob-storage