2014-06-19 67 views
2

我在Python Azure SDK中遇到問題,並且在Stack Overflow和Msdn論壇中都沒有找到任何東西。Python Azure SDK:使用list_blobs獲得超過5.000的結果

我想使用Azure SDK 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: 
     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()已解析出斑點的響應。

但是,如果是這樣的話,我該如何真正以有意義的方式使用標記?

對不起,如果這是一個愚蠢的問題,但這實際上是第一個我沒有找到答案,即使經過廣泛搜索。

乾杯!

回答

1

SDK在名爲next_marker的變量中返回連續令牌。你應該使用它來獲得下一組斑點。以下面的代碼爲例。在這裏,我一次列出容器中的100個斑點:

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.上面的代碼在最後一次迭代中引發異常。不知道爲什麼。但它應該給你一個想法。

+0

哦,它是'下一個'!我現在真的覺得很蠢。你是怎麼弄出來的?只是爲了我可以確保自己解決我的下一個問題:) – user3755680

+0

不要難過:) ...我最終修改了這裏的代碼https://github.com/Azure/azure-sdk-for -python/blob/master/azure/storage/__init __ .py#L381查看返回的屬性。不是很明顯,我必須說。爲了將來的參考,您可以在這裏查看SDK的源代碼:https://github.com/Azure/azure-sdk-for-python。 HTH。 –

+0

啊,我明白了!我實際上檢查了list_blobs函數的源代碼,但我從來沒有想過檢查解析代碼>。< 無論如何 - 感謝您的幫助! – user3755680

相關問題