Python - 如何获取Azure连续令牌?

时间:2016-01-08 15:01:22

标签: python azure azure-table-storage

我尝试使用Python从Microsoft Azure查询表存储。我一直在使用这个库:https://pypi.python.org/pypi/azure-storage/0.20.3

查询表存储并不是太难,但我不能为我的生活弄清楚如何获取延续令牌。我已经看过几个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。

1 个答案:

答案 0 :(得分: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功能的文档)