You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure DevOps Python API v7.0+中获取分页结果的continuation token

在Azure DevOps Python API 7.0+版本中获取continuation_token分页获取结果的方法

在Azure DevOps Python API旧版本(≤6.0.0b4)中,调用get_test_suites_for_plan这类方法会返回包含value列表和continuation_token的响应对象,可直接通过令牌分页拉取剩余结果。但7.0+版本的方法直接返回结果列表,不再暴露令牌,想要继续分页获取剩余内容,可以按以下方式操作:

核心思路

新版本SDK虽然将返回值简化为结果列表,但客户端会保留最后一次请求的完整响应信息。分页所需的continuation_token通常存储在响应头的x-ms-continuationtoken字段中,可通过客户端的_last_response属性获取。

代码示例

# 初始化客户端(示例代码)
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

creds = BasicAuthentication("", "你的个人访问令牌(PAT)")
conn = Connection(base_url="https://dev.azure.com/你的组织名", creds=creds)
test_client = conn.clients.get_test_client()

all_suites = []
continuation_token = None

while True:
    # 传入continuation_token参数发起请求
    current_suites = test_client.get_test_suites_for_plan(
        project="你的项目名",
        plan_id=你的测试计划ID,
        continuation_token=continuation_token
    )
    all_suites.extend(current_suites)
    
    # 从最后一次响应的请求头中提取令牌
    last_response = test_client._last_response
    continuation_token = last_response.headers.get("x-ms-continuationtoken")
    
    # 无令牌时终止循环
    if not continuation_token:
        break

注意事项

  • _last_response是SDK内部属性(以下划线开头),未来版本可能存在变动风险。
  • 若后续SDK官方更新了分页相关的公开API,建议优先使用官方提供的标准方式。

内容的提问来源于stack exchange,提问作者Jean-Francois T.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 01:02:26