Python中的Azure SDK:使用list_blobs获得超过5.000结果 [英] Python Azure SDK: Using list_blobs to get more than 5.000 Results
问题描述
我有使用Python SDK Azure的麻烦,没有发现任何东西都对堆栈溢出,并在MSDN论坛。
I'm having trouble with the Python Azure SDK and haven't found anything both on Stack Overflow and in the Msdn Forums.
我想使用的Azure SDK的list_blobs()来获取斑点的名单 - 有超过5.000(这是max_result)。
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).
如果我看一看在SDK,然后我自己看下面的code:
If I take a look at the code in the SDK itself then I see the following:
def list_blobs(self, container_name, prefix=None, marker=None,
maxresults=None, include=None, delimiter=None):
有关'标记'是描述:
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结果浑然不觉。如果我尝试这样的事:
My problem is that I'm unaware on how to use the marker to get the next set of 5.000 results. If I try something like this:
blobs = blobservice.list_blobs(target_container, prefix= prefix)
print(blobs.marker)
则该标记总是空的,我以为是因为list_blobs()已解析出斑点的响应。
then the marker is always empty, which I assume is because list_blobs() already parses the blobs out of the response.
但如果是这样的话那我怎么实际使用的标记以有意义的方式?
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.
干杯!
推荐答案
SDK返回延续标记在一个名为变量 next_marker
。你应该用它来获得下一组的斑点。请参阅下面的code作为一个例子。在这里我从容器中列出100水滴在一个时间:
SDK returns the continuation token in a variable called next_marker
. You should use that to get the next set of blobs. See the code below as an example. Here I'm listing 100 blobs from a container at a time:
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"
P.S。上面的code抛出的最后一次迭代例外。不知道为什么。但它应该给你一个想法。
P.S. The code above throws an exception on the last iteration. Not sure why. But it should give you an idea.
这篇关于Python中的Azure SDK:使用list_blobs获得超过5.000结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!