如何通过azure-devops-python-api获取仪表板列表

How to get a list of dashboards through azure-devops-python-api

我正在尝试使用 azure-devops-python-api 获取仪表板列表。 我不知道如何正确连接库以获取仪表板列表并使用它们。 我所做的是:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0 import DashboardClient 
import pprint
import requests
import json

personal_access_token = 'PAT'
organization_url = 'https://dev.azure.com/Orgname/'
team_context = 'Orgname'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

dashboard_resp = DashboardClient(base_url=organization_url, creds=credentials)
dashboards = dashboard_resp.get_dashboards_by_project('', team_context)

当我尝试执行这段代码时,出现错误

Traceback (most recent call last):
  File "az-dev-dash.py", line 16, in <module>
    dashboard_resp = azure.DashboardClient(base_url=organization_url, creds=credentials)
AttributeError: module 'azure.devops.v6_0' has no attribute 'DashboardClient'

您可以使用下面的 Python 脚本列出特定项目中的仪表板 python。

这里是python代码:

from re import T
from azure.devops.connection import Connection
from azure.devops.v6_0.dashboard.models import Dashboard, TeamContext
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.dashboard.dashboard_client import DashboardClient 
import pprint
import requests
import json

personal_access_token = '<PATToken>'
organization_url = 'https://dev.azure.com/<OrgnName>' ##OrganisationalUrl

team_context=TeamContext('<projectName>')

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
core_client = connection.clients.get_core_client()
dashboard_resp = DashboardClient(base_url=organization_url, creds=credentials)
dashboards = dashboard_resp.get_dashboards_by_project(team_context)
for item in dashboards:
 print(item)

这里是示例输出以供参考:

或者,您可以this休息API,到list the dashboards in the project