首页 > 解决方案 > 仅使用 Python 而不是整个 blob 检索部分 Azure 文本 blob

问题描述

这是我的应用程序用于检索 Azure 文本 blob 的 Python 函数。这是函数的文档gen_blob_to_text(当您单击页面时,Ctrl+F 并搜索函数的名称)。

def get_text_blob(self, archive_url):
    container, archive_location = paths.extract_url_elements(archive_url)

    blob = None
    try:
        blob = self.blob_service.get_blob_to_text(container_name = container,
                                                  blob_name = archive_location)
        self.logger.debug('Retrieved ' + archive_url)
    except:
        self.logger.error('Failed to retrieve text blob {} {}'.format(archive_url, traceback.format_exc()))

    return blob

运行此函数并blob取回对象(在我的情况下是一些 HTML 内容)后,如果我在 Visual Studio 2017 中检查它,我会得到以下不完整的 blob 文本,如...

在此处输入图像描述

我的问题是:如何获取全文而不是其中的一部分?我究竟做错了什么?

标签: pythonazurevisual-studio-2017azure-blob-storage

解决方案


我无法在我这边重现您的问题。我通过以下代码成功获取了 blob 内容:

from azure.storage.blob import (
    BlockBlobService
)

accountName = "***"
accountKey = "***"
containerName = "test1"

blobService = BlockBlobService(account_name=accountName, account_key=accountKey)

blobContent = blobService.get_blob_to_text(containerName,"storage.html")

print(blobContent.content)

我尝试在Text Visualizer中对其进行调试。如果我正确拖动窗口,它可以完全显示。

在此处输入图像描述

希望它可以帮助你。


推荐阅读