使用 Push API 将文件上传到 azure devops 时,对象 '"' 不存在。'显示 "typeName":"Microsoft.TeamFoundation.Git
while uploading a file into azure devops using Push API, The object '"' does not exist.' get displayed "typeName":"Microsoft.TeamFoundation.Git
我正在尝试使用以下 API 将文件添加到 respos 文件夹中:
ado_req_headers_ATT = {'Content-Type':'application/octet-stream'}
Get_Branch_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/refs?filter=heads/&api-version=6.0')
print(Get_Branch_url)
Get_Branch_Details = requests.get(url=Get_Branch_url,headers=ado_req_headers_ATT,auth=('',ADO_AUTH_PAT))
#print(Get_Branch_Details.status_code)
print(Get_Branch_Details.text)
Get_Branch_Details=Get_Branch_Details.json()
for item in Get_Branch_Details["value"]:
if item["name"] == **'refs/heads/XXX'**:
old_object_ID = item["objectId"]
old_object_name= item["name"]
print(old_object_name,":-",old_object_ID) **## Prints refs/heads/XXX : YYYYYYYYYYYYYYYYYYYYYY**
以上url的回复包括:
{
"value": [
{...
**"name": "refs/heads/XXX",
"objectId": "YYYYYYYYYYYYYYYYYYYYYY",**
"creator": {
"displayName": "AAAAAAAAAA",
"url": "https://spsprodsin1.vssps.visualstudio.com/UUUUUU",
"_links": {
"avatar": {
"href": "https://dev.azure.com/TTTTTT"
}
},
"id": "MMMMMMMMM",
"uniqueName": "PPPPPPPP",
并将此对象 ID:YYYYYYYYYYYYYYYYYYYYY 视为旧 ObjectID 并尝试将文件推入路径:refs/heads/XXX 使用以下 API:
###### Push a File in Ref_Devops-dev ###############################
ado_req_headers_ATT = {"Content-Type":"application/json-patch+json"}
push_file_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/pushes?api-version=6.0')
Body_data = {"refUpdates": [{"name": refs/heads/XXX,"oldObjectId":YYYYYYYYYYYYYYYYYYYYYY}],"commits":[{"comment": "Added text file.","changes":[{"changeType": "add","item": {"path":"/test.txt"},"newContent": {"content": "# Tasks\n\n* Item 1\n* Item 2","contentType": "rawtext"}}]}]}
Body_data = json.dumps(Body_data)
print(Body_data)
Push_file= requests.post(url=push_file_url,headers=ado_req_headers_ATT,data=Body_data,auth=('',ADO_AUTH_PAT))
print(Push_file.json())
print(Push_file.status_code)
print(Push_file.text)
但回复是:
{"$id":"1","innerException":null,"message":"TF401035: The object 'YYYYYYYYYYYYYYYYYYYYYY' does not exist.","typeName":"Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitObjectDoesNotExistException","errorCode":0,"eventId":3000}
当然还缺少最后一步和基本步骤。任何建议请
可以通过引用提交 API 而不是提及 API 并获取最新的提交 ID 来消除上述错误。
我正在尝试使用以下 API 将文件添加到 respos 文件夹中:
ado_req_headers_ATT = {'Content-Type':'application/octet-stream'}
Get_Branch_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/refs?filter=heads/&api-version=6.0')
print(Get_Branch_url)
Get_Branch_Details = requests.get(url=Get_Branch_url,headers=ado_req_headers_ATT,auth=('',ADO_AUTH_PAT))
#print(Get_Branch_Details.status_code)
print(Get_Branch_Details.text)
Get_Branch_Details=Get_Branch_Details.json()
for item in Get_Branch_Details["value"]:
if item["name"] == **'refs/heads/XXX'**:
old_object_ID = item["objectId"]
old_object_name= item["name"]
print(old_object_name,":-",old_object_ID) **## Prints refs/heads/XXX : YYYYYYYYYYYYYYYYYYYYYY**
以上url的回复包括:
{
"value": [
{...
**"name": "refs/heads/XXX",
"objectId": "YYYYYYYYYYYYYYYYYYYYYY",**
"creator": {
"displayName": "AAAAAAAAAA",
"url": "https://spsprodsin1.vssps.visualstudio.com/UUUUUU",
"_links": {
"avatar": {
"href": "https://dev.azure.com/TTTTTT"
}
},
"id": "MMMMMMMMM",
"uniqueName": "PPPPPPPP",
并将此对象 ID:YYYYYYYYYYYYYYYYYYYYY 视为旧 ObjectID 并尝试将文件推入路径:refs/heads/XXX 使用以下 API:
###### Push a File in Ref_Devops-dev ###############################
ado_req_headers_ATT = {"Content-Type":"application/json-patch+json"}
push_file_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/pushes?api-version=6.0')
Body_data = {"refUpdates": [{"name": refs/heads/XXX,"oldObjectId":YYYYYYYYYYYYYYYYYYYYYY}],"commits":[{"comment": "Added text file.","changes":[{"changeType": "add","item": {"path":"/test.txt"},"newContent": {"content": "# Tasks\n\n* Item 1\n* Item 2","contentType": "rawtext"}}]}]}
Body_data = json.dumps(Body_data)
print(Body_data)
Push_file= requests.post(url=push_file_url,headers=ado_req_headers_ATT,data=Body_data,auth=('',ADO_AUTH_PAT))
print(Push_file.json())
print(Push_file.status_code)
print(Push_file.text)
但回复是:
{"$id":"1","innerException":null,"message":"TF401035: The object 'YYYYYYYYYYYYYYYYYYYYYY' does not exist.","typeName":"Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitObjectDoesNotExistException","errorCode":0,"eventId":3000}
当然还缺少最后一步和基本步骤。任何建议请
可以通过引用提交 API 而不是提及 API 并获取最新的提交 ID 来消除上述错误。