gpt4 book ai didi

python - Azure Blob 存储 - 可以列出 blob,但不能删除 blob

转载 作者:行者123 更新时间:2023-12-03 01:19:42 31 4
gpt4 key购买 nike

我正在尝试从 Azure 容器中删除 blob。我能够连接到它并列出此问题中代码后面的所有 blob:Upload and Delete Azure Storage Blob using azure-storage-blob or azure-storage


CONNECT_STR = "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXXXXXXXXX;EndpointSuffix=core.windows.net"
CONTAINER_NAME = "containername/"
blob_name = "productionmap/oursoftware/intended_blob_to_use.csv"

container_client = ContainerClient.from_connection_string(conn_str=CONNECT_STR, container_name=CONTAINER_NAME)

# Delete blob
container_client.delete_blob(blob=blob_name)

我能够列出所有的 blob。我尝试使用 for 循环来遍历 blob 并获取要删除的特定 blob:

for x in bloblist:
if x.name == 'intended_blob_to_use.csv':
print(x.name)
container_client.delete_blob(blob=x)

上面的代码能够通过打印获取特定的blob名称,但无法删除它。因此它不应该与我的文件名有关。我收到的错误消息是:

Traceback (most recent call last):
File "/tmp/interpreter-input-038d73c4-068f-421b-b349-2f61f486a36b.tmp", line 25, in <module>
container_client.delete_blob(ourblobfile)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
return func(*args, **kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_container_client.py", line 1060, in delete_blob
**kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
return func(*args, **kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_blob_client.py", line 1106, in delete_blob
process_storage_error(error)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_shared/response_handlers.py", line 181, in process_storage_error
exec("raise error from None") # pylint: disable=exec-used # nosec
File "<string>", line 1, in <module>
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_blob_client.py", line 1104, in delete_blob
self._client.blob.delete(**options)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_generated/operations/_blob_operations.py", line 589, in delete
map_error(status_code=response.status_code, response=response, error_map=error_map)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/exceptions.py", line 105, in map_error
raise error
azure.core.exceptions.ResourceNotFoundError: The specified blob does not exist.
RequestId:ccd2f1dd-a01e-0078-4989-4d431e000000
Time:2022-04-11T09:49:05.7447809Z
ErrorCode:BlobNotFound
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:ccd2f1dd-a01e-0078-4989-4d431e000000
Time:2022-04-11T09:49:05.7447809Z</Message></Error>`

为什么我不能删除它?我通过连接字符串传递 key ,并且该用户在存储上设置了“所有者”。

最佳答案

使用相同的代码从我们的端进行复制后,我们收到了相同的错误。

enter image description here

就像 @Gaurav Mantri 提到的那样,是额外的尾部斜杠导致了错误,这使得它指向不同的路径并导致 BlobNotFound。

ErrorCode:BlobNotFoundContent: BlobNotFoundThe specified blob does not exist.RequestId:c647b4cb-001e-002c-6ffa-4e4ea0000000Time:2022-04-13T05:50:27.6230552Z

关于python - Azure Blob 存储 - 可以列出 blob,但不能删除 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71825893/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com