2016-01-08 31 views
1

我想使用Python從Microsoft Azure查詢表存儲。我一直在使用這個庫:https://pypi.python.org/pypi/azure-storage/0.20.3Python - 如何獲取Azure延續性令牌?

查詢表存儲並不是太困難,但我不能爲我的生活弄清楚如何獲取連續令牌。我已經看到了幾個C#示例,甚至是一個Java示例,但不是Python的一個示例。

這是我使用'top'參數抓取一千個條目的方法。在這種情況下,我應該在回覆中留下一個延續標記。每本手冊: https://msdn.microsoft.com/en-us/library/azure/dd135718.aspx

def get_thousand_chunk(self, filter, select, top, next_partition_key, next_row_key): 
    print "Getting table storage..." 
    list = self.table_service.query_entities(self.table_name, top=1000) 
    #result.x_ms_continuation['NextPartitionKey'] 
    ''' 
    ---LIBRARY DOCUMENTATION WITHIN query_entities METHOD--- 

    Get entities in a table; includes the $filter and $select options. 

    table_name: 
     Table to query. 
    filter: 
     Optional. Filter as described at 
     http://msdn.microsoft.com/en-us/library/windowsazure/dd894031.aspx 
    select: 
     Optional. Property names to select from the entities. 
    top: 
     Optional. Maximum number of entities to return. 
    next_partition_key: 
     Optional. When top is used, the next partition key is stored in 
     result.x_ms_continuation['NextPartitionKey'] 
    next_row_key: 
     Optional. When top is used, the next partition key is stored in 
     result.x_ms_continuation['NextRowKey'] 
    ''' 

    print "Got table storage" 
    return self._mapper(list) 

顯然這個代碼是一項正在進行的工作,所以我已經top=1000硬編碼在方法調用用於測試的參數。我也意識到我目前沒有使用next_partition_keynext_row_key但是,我願意接受所有建設性的批評。

如果您需要更多信息才能正確回答,請讓我知道。

謝謝大家提前。

我正在使用Python 2.7.8。

回答

2

請嘗試以下代碼:

import os 
import json 
from azure import * 
from azure.storage import * 
from azure.storage.table import TableService, Entity 

table_service = TableService(account_name='account-name', account_key='account-key') 
list = table_service.query_entities('table-name', top=100) 
if hasattr(list, 'x_ms_continuation'): 
    nextPartitionKey = list.x_ms_continuation['NextPartitionKey'] 
    nextRowKey = list.x_ms_continuation['NextRowKey'] 
    print nextPartitionKey 
    print nextRowKey 

編號:https://github.com/Azure/azure-storage-python/blob/master/azure/storage/table/tableservice.py(檢查query_entities函數文檔)

+0

這就是答案。謝謝! – john14073

+0

查看測試以及(https://github.com/Azure/azure-storage-python/blob/master/tests/test_storage_table.py#L638)。另外要注意的是:我們正在對這個庫進行重大重構,即將推出的版本會自動(並且懶洋洋地)遵循繼續令牌。 :) –