gpt4 book ai didi

python - 如何使用 Python 进行用户身份验证 Azure DevOps

转载 作者:行者123 更新时间:2023-12-03 00:03:36 27 4
gpt4 key购买 nike

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

我已经生成了个人访问 token 。以下是我用于访问 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

最佳答案

引用教程:

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) 创建具有基本身份验证的连接。

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

关于python - 如何使用 Python 进行用户身份验证 Azure DevOps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60877761/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com