简体   繁体   English

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

[英]Python Azure SDK: Using list_blobs to get more than 5.000 Results

I'm having trouble with the Python Azure SDK and haven't found anything both on Stack Overflow and in the Msdn Forums. 我遇到了Python Azure SDK的问题,并且在Stack Overflow和Msdn论坛中都没有找到任何东西。

I want to use Azure SDKs list_blobs() to get a list of blobs - there are more than 5.000 (which is the max_result). 我想使用Azure SDKs list_blobs()来获取blob列表 - 超过5.000(这是max_result)。

If I take a look at the code in the SDK itself then I see the following: 如果我看一下SDK本身的代码,我会看到以下内容:

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

The description for 'Marker' being: '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.

My problem is that I'm unaware on how to use the marker to get the next set of 5.000 results. 我的问题是我不知道如何使用标记来获得下一组5.000结果。 If I try something like this: 如果我尝试这样的事情:

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

then the marker is always empty, which I assume is because list_blobs() already parses the blobs out of the response. 然后标记总是空的,我假设是因为list_blobs()已经从响应中解析了blob。

But if that is the case then how do I actually use the marker in a meaningful way? 但如果是这种情况,那么我如何以有意义的方式实际使用标记呢?

I'm sorry if this is a stupid question but this actually is the first one that I didn't find an answer for, even after searching extensively. 我很抱歉,如果这是一个愚蠢的问题,但这实际上是第一个我找不到答案的,即使经过广泛搜索。

Cheers! 干杯!

SDK returns the continuation token in a variable called next_marker . SDK在名为next_marker的变量中返回延续令牌。 You should use that to get the next set of blobs. 您应该使用它来获取下一组blob。 See the code below as an example. 请参阅下面的代码作为示例。 Here I'm listing 100 blobs from a container at a time: 在这里,我一次列出一个容器中的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"

PS The code above throws an exception on the last iteration. PS上面的代码在最后一次迭代时引发异常。 Not sure why. 不知道为什么。 But it should give you an idea. 但它应该给你一个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM