【问题标题】:How to put in user authentication Azure DevOps with Python如何使用 Python 进行用户身份验证 Azure DevOps
【发布时间】:2020-03-26 23:28:54
【问题描述】:

我正在尝试使用 Python 访问 Azure DevOps。在 IntelliJ 中运行以下代码后,我收到一条错误消息,提示“请求的资源需要用户身份验证:”。提供用户身份验证所需的 Python 代码是什么?

我已经生成了个人访问令牌。这是我用来访问 Azure DevOps 的原始 Python 代码的链接。 https://github.com/Microsoft/azure-devops-python-api

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

# Fill in with your personal access token and org URL
personal_access_token = 'token'
organization_url = 'url'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)

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

enter image description here

【问题讨论】:

    标签: python azure authentication token devops


    【解决方案1】:

    参考教程:

    from azure.devops.connection import Connection
    from msrest.authentication import BasicAuthentication
    
    # 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()
    
    

    您需要通过connection = Connection(base_url=organization_url, creds=credentials) 使用基本身份验证创建连接。

    请检查您是否已将其添加到您的代码中。根据我的测试,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多