【问题标题】:How to connect VSTS through Python by VSTS personal token to query and fetch the query results如何通过 VSTS 个人令牌通过 Python 连接 VSTS 查询并获取查询结果
【发布时间】:2019-08-30 16:17:59
【问题描述】:

我想使用我的个人令牌通过 python 代码连接 VSTS(Azure)。主要是查询vsts,通过python代码得到查询结果

我正在尝试使用 Spyder(Python 3.6) 处理不同的代码,但它不起作用。

请分享示例 python 代码以从 VSTS 获取查询结果。

【问题讨论】:

  • 你能分享一下你试过的代码,哪些没用吗?

标签: python-3.x azure azure-devops


【解决方案1】:

VSTS个人token如何通过Python连接VSTS查询获取查询结果

使用VSTS个人令牌通过Python连接Azure Devops,可以使用如下连接代码:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint

# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

查看文档Azure DevOps Python API了解更多详情。

如果想用 Python REST API 查询和获取查询结果,可以参考this thread

此外,由于您没有分享有关您尝试过的代码和无效代码的详细信息,因此我无法给您准确的答案,但 MS 提供了一些示例如何使用 Python REST API:

Python samples for Azure DevOps

希望这会有所帮助。

【讨论】:

  • 非常感谢您的支持。我正在使用以下代码连接 azure.from vsts.vss_connection import VssConnection from msrest.authentication import BasicAuthentication import pprint token = 'MyToken' team_instance = 'myorg.com' credentials = BasicAuthentication('',token) connection = VssConnection(base_url= team_instance, creds=credentials) core_client = connection.get_client('vsts.core.v4_0.core_client.CoreClient') team_projects = core_client.get_projects() 用于 team_projects 中的项目:pprint.pprint(project._dict_)
  • @Shyam,那你现在有什么问题?您可以使用您正在使用的 python 脚本和错误日志来更新您的问题。
  • 谢谢@Leo Liu,上面的回答对我很有帮助。我能够实现它
猜你喜欢
  • 2018-12-27
  • 1970-01-01
  • 2018-07-29
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
  • 2018-11-23
  • 2020-09-22
  • 2012-08-30
相关资源
最近更新 更多