【问题标题】:AuthorizationPermissionMismatch when Python Function App attempts to read filePython Function App 尝试读取文件时的 AuthorizationPermissionMismatch
【发布时间】: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


    【解决方案1】:

    system-assigned-identity 还需要角色'Storage Queue Data Contributor '。并且要在日志中显示文件的内容,“download_stream”应替换为 download_stream.readall()。

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 2018-04-27
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      相关资源
      最近更新 更多