![](/img/trans.png)
[英]Azure SDK for Python: How to limit results in list_blobs()?
[英]Python Azure SDK: Using list_blobs to get more than 5.000 Results
我遇到了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"
PS上面的代碼在最后一次迭代時引發異常。 不知道為什么。 但它應該給你一個想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.