【问题标题】:While downloading azure blobs to local file system an exception occurs将 azure blob 下载到本地文件系统时发生异常
【发布时间】:2018-08-30 19:54:46
【问题描述】:

在将 azure blob 下载到本地文件系统时,出现以下异常:

Client-Request-ID=99bdb0e4-2d1c-11e8-8fe6-00155dbf7128 Retry policy did not allow for a retry: Server-Timestamp=Wed, 21 Mar 2018 15:29:09 GMT, Server-Request-ID=1e7ab8f5-101e-0076-5329-c16a24000000, HTTP status code=404, Exception=The specified blob does not exist.
ErrorCode: BlobNotFound<?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:1e7ab8f5-101e-0076-5329-c16a24000000Time:2018-03-21T15:29:09.6565984Z</Message></Error>.
Traceback (most recent call last):
  File "C:\Program Files\Commvault\ContentStore\Automation\CloudApps\CloudAppsUtils\cahelper.py", line 483, in download_contents_azure
    session.get_blob_to_path(container_name,fl,fl)
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\blob\baseblobservice.py", line 1817, in get_blob_to_path
    timeout)
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\blob\baseblobservice.py", line 2003, in get_blob_to_stream
    raise ex
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\blob\baseblobservice.py", line 1971, in get_blob_to_stream
    _context=operation_context)
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\blob\baseblobservice.py", line 1695, in _get_blob
    operation_context=_context)
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\common\storageclient.py", line 354, in _perform_request
    raise ex
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\common\storageclient.py", line 289, in _perform_request
    raise ex
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\common\storageclient.py", line 275, in _perform_request
    HTTPError(response.status, response.message, response.headers, response.body))
  File "C:\Program Files\Python36\lib\site-packages\azure\storage\common\_error.py", line 111, in _http_error_handler
    raise AzureHttpError(message, http_error.status)
azure.common.AzureMissingResourceHttpError: The specified blob does not exist.ErrorCode: BlobNotFound
<?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:1e7ab8f5-101e-0076-5329-c16a24000000
Time:2018-03-21T15:29:09.6565984Z</Message></Error>

我正在使用以下代码下载 blob:

def download_contents_azure(self, account_name, account_key, content):
    session=self.create_session_azure(account_name,account_key)
    os.mkdir('in place')
    os.chdir('in place')

    for item in content:
        # s = os.path.basename(item)

        path_to_file = ("/".join(item.strip("/").split('/')[1:]))
        container_name = Path(item).parts[1]
        gen = session.list_blobs(container_name)
        li = []

        for i in gen:
            li.append(i.name)

        if path_to_file in li:
            fl = os.path.basename(path_to_file)

            print(fl)
            c = self.splitall(item)

            for i in range(1,len(c)-1):
                if path.exists(c[i]) is False:
                    os.mkdir(c[i])
                os.chdir(c[i])

            session.get_blob_to_path(container_name,fl,fl)

            for i in range(1,len(c)-1):
                os.chdir("..")
        else:
            c = self.splitall(item)
            for i in range(1,len(c)):
                os.mkdir(c[i])
                os.chdir(c[i])

            generator = session.list_blobs(container_name,path_to_file+'/',delimiter='/')

            for blob in generator:
                bl = os.path.basename(blob.name)
                session.get_blob_to_path(container_name,bl,bl)

我有一条天蓝色的道路 (/container/folder/subfolder)。
我正在尝试下载subfolder 下的结构和所有文件。 subfolder 下的第一个文件被下载,然后我遇到了上述异常。因此,我无法循环并打印下一个项目。

想法?

【问题讨论】:

  • 您拥有的每一行代码无需换行。它使帖子过长,难以阅读和理解。
  • fl 看起来像什么?还要安装 fiddler 并查看请求并将其粘贴到此处,以便我们帮助您解决请求失败的原因。

标签: python python-3.x azure azure-storage azure-blob-storage


【解决方案1】:

仔细检查您的线路 session.get_blob_to_path(container_name,fl,fl)

fl 对应于 blob_name

documentation here 表示第二个参数是 blob_name,而第三个参数是文件系统上要下载的文件路径。

我认为你的 blob 名称是错误的。因此它不存在。

注意:考虑安装fiddler,以便查看网络跟踪。它允许您查看原始请求。

【讨论】:

  • Saher,我认为 blob 名称没有问题。它被下载,然后发生此异常。使用提琴手,我看到很多证书错误。
  • 在 fiddler 中找到 GetBlob 调用是您的代码实际调用的,http 结果 200 是否成功?
  • 我在做了一些异常处理后摆脱了这个。
  • @Sruthi 这没有意义。如果 blob 存在,您首先不应该遇到异常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
  • 2021-05-22
  • 2019-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-03
相关资源
最近更新 更多