加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python Azure SDK:使用list_blobs获得超过5.000个结果

发布时间:2020-12-20 13:43:12 所属栏目:Python 来源:网络整理
导读:我遇到了 Python Azure SDK的问题,并且在Stack Overflow和Msdn论坛中都没有找到任何东西. 我想使用Azure SDKs list_blobs()来获取blob列表 – 超过5.000(这是max_result). 如果我看一下SDK本身的代码,我会看到以下内容: def list_blobs(self,container_name
我遇到了 Python Azure SDK的问题,并且在Stack Overflow和Msdn论坛中都没有找到任何东西.

我想使用Azure SDKs list_blobs()来获取blob列表 – 超过5.000(这是max_result).

如果我看一下SDK本身的代码,我会看到以下内容:

def list_blobs(self,container_name,prefix=None,marker=None,maxresults=None,include=None,delimiter=None):

‘Marker’的描述是:

marker:
        Optional. A string value that identifies the portion of the list
        to be returned with the next list operation. The operation returns
        a marker value within the response body if the list returned was
        not complete. The marker value may then be used in a subsequent
        call to request the next set of list items. The marker value is
        opaque to the client.

我的问题是我不知道如何使用标记来获得下一组5.000结果.如果我尝试这样的事情:

blobs = blobservice.list_blobs(target_container,prefix= prefix)            
    print(blobs.marker)

然后标记总是空的,我假设是因为list_blobs()已经从响应中解析了blob.

但如果是这种情况,那么我如何以有意义的方式实际使用标记呢?

我很抱歉,如果这是一个愚蠢的问题,但这实际上是第一个我找不到答案的,即使经过广泛搜索.

干杯!

解决方法

SDK在名为next_marker的变量中返回延续令牌.您应该使用它来获取下一组blob.请参阅下面的代码作为示例.在这里,我一次列出一个容器中的100个blob:

from azure import *
from azure.storage import *

blob_service = BlobService(account_name='<accountname>',account_key='<accountkey>')
next_marker = None
while True:
    blobs = blob_service.list_blobs('<containername>',maxresults=100,marker=next_marker)
    next_marker = blobs.next_marker
    print(next_marker)
    print(len(blobs))
    if next_marker is None:
        break
print "done"

附:上面的代码在最后一次迭代时抛出异常.不知道为什么.但它应该给你一个想法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读