【发布时间】:2022-01-25 02:24:07
【问题描述】:
我目前正在使用带有 azure.storage.blob 12.9.0 版和 azure.core 1.14.0 版的 python 3.8.8。
我正在使用 azure.storage.blob 包下载多个文件。我的代码如下所示
from azure.storage.blob import ContainerClient
from azure.core.exceptions import ResourceNotFoundError, AzureError
from time import sleep
max_attempts = 5
container_client = ContainerClient(DETAILS)
for file in multiple_files:
attempts = 0
while attempts < max_attempts:
try:
data = container.download_blob(file).readall()
break
except ResourceNotFoundError:
# log missing data
break
except AzureError:
# This is mainly here as connections seem to drop randomly.
attempts += 1
sleep(1)
if attempts >= max_attempts:
#log connection error
#do something with the data.
它似乎运行良好,我没有看到任何数据丢失。但是,在我的终端中,我不断收到消息
Unable to stream download: ("Connection broken: ConnectionResetError(104, 'Connection reset by peer')", ConnectionResetError(104, 'Connection reset by peer'))
这似乎是一条 TCP 104 返回消息,但未由 azure 模块处理。我的问题如下。
- 此消息来自哪里?我在使用的任何软件包中都看不到它。
- 如何更好地处理此错误?它似乎没有被捕获为异常,因为它没有使我的代码崩溃。
- 我可以将此打印到日志中吗?
【问题讨论】:
标签: python azure error-handling tcp azure-blob-storage