我正在尝试使用带有python和python请求包的GitLab Merge Request API创建合并请求。这是我的代码片段
import requests, json
MR = 'http://www.gitlab.com/api/v4/projects/317/merge_requests'
id = '317'
gitlabAccessToken = 'MySecretAccessToken'
sourceBranch = 'issue110'
targetBranch = 'master'
title = 'title'
description = 'description'
header = { 'PRIVATE-TOKEN' : gitlabAccessToken,
'id' : id,
'title' : title,
'source_branch' : sourceBranch,
'target_branch' : targetBranch
}
reply = requests.post(MR, headers = header)
status = json.loads(reply.text)
但我在回复中不断收到以下消息
{'error': 'title is missing, source_branch is missing, target_branch is missing'}
我的要求应该如何更改以使其有效?
答案 0 :(得分:4)
除PRIVATE-TOKEN
外,所有参数都应作为表格编码参数传递,这意味着:
header = {'PRIVATE-TOKEN' : gitlabAccessToken}
params = {
'id' : id,
'title' : title,
'source_branch' : sourceBranch,
'target_branch' : targetBranch
}
reply = requests.post(MR, data=params, headers=header)