Azure:在 blob_client 中找不到资源

标签 azure azure-active-directory azure-functions azure-blob-storage

我正在尝试使用 python 脚本删除我的 azure blob,为此我使用 azure.storage 库中的 BlobClient

这是代码,我正在尝试运行:

import json, sys, os, time
from azure.storage.blob import BlobServiceClient, PublicAccess, BlobClient


endpoint = os.environ['COMPUTER_VISION_ENDPOINT']
subscription_key = os.environ['COMPUTER_VISION_SUBSCRIPTION_KEY']

text_recognition_url = endpoint + "/vision/v3.0/read/analyze"

file_name = input("Enter the file name: ")
image_url = "https://textimage.blob.core.windows.net/handwritten-text/" + file_name

blob_client = BlobClient.from_blob_url(blob_url=image_url)

blob_client.delete_blob()
print("Done")

虽然 blob 和容器存在于 azure 存储帐户中,但它会引发以下错误:

azure.core.exceptions.ResourceNotFoundError: The specified resource does not exist.

我哪里错了?

使用 python 脚本删除特定打开的 blob 的更好方法是什么?

最佳答案

import os
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

blob_service_client = BlobServiceClient.from_connection_string(os.getenv('str'))
container_client = blob_service_client.get_container_client("test")
blob_client = blob_service_client.get_blob_client("test", "test.txt")
blob_client.delete_blob()

上面的代码在我这边工作得很好。(您可以用动态值替换容器名称和 blob 名称。)

看看官方文档:

https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blobserviceclient?view=azure-python

https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blobclient?view=azure-python#methods

当您遇到NoneType对象没有属性“rstrip”时,这意味着您应该为该方法提供连接字符串。

关于Azure:在 blob_client 中找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63499378/

相关文章:

azure - 下载的许可证不足 Azure/Visual Studio Online 和 Visual Studio 2013

azure - 如何使用 powershell Az 模块为 Azure AD 应用程序提供所需权限的访问权限

azure - Cosmos DB - 在Where条件中使用嵌套查询输出

configuration - 如何从Azure配置文件获取所有配置设置?

azure - 扩展 Azure Active Directory 访问 token 声明

azure - 将长时间运行的作业解耦为 azure 函数..如何获取整体状态?

c# - 如何将 'Microsoft.CognitiveServices.Speech' 命名空间与 Azure Functions 一起使用?

azure - 在 Azure Functions 中重新启动 Poison blob

c# - Azure Active Directory 登录重定向循环

azure - AADSTS76020 : Azure AD SSO with Signin certificate cannot authenticate graph client