问题描述
@H_404_0@我正在尝试使用python脚本删除 azure blob ,为此,我正在使用azure.storage库中的 BlobClient 。
@H_404_0@这是代码,我正在尝试运行:
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")
@H_404_0@尽管,blob和容器存在于azure存储帐户中,但它引发了以下错误:
azure.core.exceptions.ResourceNotFoundError: The specified resource does not exist.
@H_404_0@我在哪里错了?
@H_404_0@使用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名称。)
看看官方文档:
面对NoneType object has no attribute 'rstrip'
时,这意味着应为该方法提供连接字符串。