![](/img/trans.png)
[英]How to add a user to Azure DevOps using it's python client API?
[英]How to put in user authentication Azure DevOps with Python
我正在嘗試使用 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()
參考教程:
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)
創建具有基本身份驗證的connection = Connection(base_url=organization_url, creds=credentials)
。
請檢查您是否已將其添加到您的代碼中。 根據我的測試,一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.