使用python azure-devops软件包时,如何使用PAT进行身份验证?

时间:2019-07-26 13:58:34

标签: python azure azure-devops azure-devops-rest-api

GitHub上的Microsoft Azure-DevOps软件包提供了一个在READ-ME页面上使用其库的单一用例

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)

# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()

# Get the list of projects in the org
projects = core_client.get_projects()

# Show details about each project in the console
for project in projects:
    pprint.pprint(project.__dict__)

我在网上四处张望,没有找到任何文档或方法来弄清楚如何安装或使用“ mrest.authentication”导入,因此无法创建与Azure-DevOps的连接或完全使用此库。

使用pip install mrest表示在网上找不到匹配的程序包,而且我无法弄清楚如果Microsoft是私有库,为什么Microsoft会将其包含在文档中。

如果任何人都知道使用azure-DevOps包创建连接的解决方法,如何安装mrest包或访问Azure DevOps REST API的更好方法,请告诉我,谢谢!

2 个答案:

答案 0 :(得分:0)

您将需要: pip安装azure-devops

答案 1 :(得分:0)

您需要安装msrest软件包,而不是mrest: pip3 install msrest