类似于 here 发布的问题,我正在尝试通过 python 管理 Azure DevOps 工作项。
接受的答案是指官方 Azure DevOps Python API 文档 和一些 示例代码 看起来可能已经过时了。
这是我尝试运行的脚本的简化版本:
from azure.devops.connection import Connection
from azure.devops.v7_1.work_item_tracking import JsonPatchOperation
from msrest.authentication import BasicAuthentication
personal_access_token = "MY_PAT"
organization_url = f'https://dev.azure.com/{MY_ORG}'
# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
core_client = connection.clients.get_core_client() # core client --> used to get project
project = core_client.get_project(MY_PROJECT_ID)
wit_client = connection.clients.get_work_item_tracking_client() # work item tracking client
# this code is recycled from the azure example code posted above
def _create_work_item_field_patch_operation(op, field, value):
path = '/fields/{field}'.format(field=field)
return _create_patch_operation(op=op, path=path, value=value)
def _create_patch_operation(op, path, value):
patch_operation = JsonPatchOperation()
patch_operation.op = op
patch_operation.path = path
patch_operation.value = value
patch_operation._from = None
return patch_operation
patch_document = []
patch_document.append(_create_work_item_field_patch_operation('add', 'System.Title', "Testing"))
patch_document.append(_create_work_item_field_patch_operation('add', 'System.Description', "Hoping to create a new work item."))
wit_client.create_work_item(document=patch_document, project=project, type="Bug")
当我执行这段代码时,出现以下错误:
azure.devops.exceptions.AzureDevOpsClientRequestError: Operation returned a 400 status code.
我想知道是否有人知道为什么我会收到 400 状态码。