[英]How to get a list of dashboards through azure-devops-python-api
I am trying to get a list of dashboards using azure-devops-python-api .我正在尝试使用azure-devops-python-api获取仪表板列表。 I can't figure out how to connect the libraries correctly to get the list of dashboards and work with them.
我不知道如何正确连接库以获取仪表板列表并使用它们。 What I've done is this:
我所做的是这样的:
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)
When I try to execute this code, I get an error当我尝试执行此代码时,出现错误
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'
You can use the below Python script to list the dashboards in a particular project using python.您可以使用下面的 Python 脚本列出使用 python 的特定项目中的仪表板。
Here is the python code:这是 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)
Here is the sample output for reference:以下是样品 output 供参考:
Alternatively, you can this Rest API, to list the dashboards in the project
.或者,您可以使用此Rest API
list the dashboards in the project
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.