TF400898:发生内部错误。 Activity 编号:1fc05eca-fed8-4065-ae1a-fc8f2741c0ea

TF400898: An Internal Error Occurred. Activity Id: 1fc05eca-fed8-4065-ae1a-fc8f2741c0ea

我正在尝试通过 azure API 将文件推送到 git 存储库,但出现 activity_id 错误。我按照他们的 documentation 并尝试在我的存储库中添加简单文件。 这是我的代码:

import requests, base64
pat_token = "xxxx-xxxxx-xxxx"
b64Val = base64.b64encode(pat_token.encode()).decode()
payload = {
 "refUpdates": [
   {
     "name": "refs/heads/main",
     "oldObjectId": "505aae1f15ae153b7fc53e8bdb79ac997caa99e6"
   }
 ],
"commits": [
  {
    "comment": "Added task markdown file.",
    "changes": [
      {
        "changeType": "add",
        "item": {
          "path": "TimeStamps.txt"
         },
        "newContent": {
          "content": "# Tasks\n\n* Item 1\n* Item 2",
          "contentType": "rawtext"
        }
      }
    ]
  }
 ]
}
headers = {
'Authorization': 'Basic %s' % b64Val,
'Content-Type': 'application/json',
}
params = (
    ('api-version', '6.0'),
)
response = requests.post('https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repo}/pushes', headers=headers, data=payload, params=params)

有人知道如何解决这个问题吗?我还在他们的开发者社区

中添加了这个 issue

我已经修复了那个错误,实际上有效载荷不是 json 格式,所以我必须把它变成 json 之后它就可以正常工作了。 像这样

response = requests.post('https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repoId}/pushes', headers=headers,  params=params, data=json.dumps(payload))