使用他们的 REST API 和 python 请求将 POST HOOK 添加到 bitbucket 存储库

add POST HOOK to a bitbucket repository using their REST API and python-requests

我正在尝试将 POST 挂钩添加到 bitbucket 存储库,但每次尝试都得到 404 个结果。

我在做:

payload = {'type': 'POST', 'URL': announce_post_hook}
content_type = {"Content-Type": "application/json"}
request_url = 'https://api.bitbucket.org/1.0/repositories/{repo_owner}/{repo_slug}/services/'                       
request_url = request_url.format(repo_owner=repo_owner, remote_url=remote_url)
requests.post(request_url, auth=(repo_user, repo_pass), data=json.dumps(payload), headers=content_type)

我也试过用这个 URL:

https://bitbucket.org/api/1.0/repositories/{repo_owner}/{repo_slug}/services/

因为是在他们 api 的不同部分中列出的那个(例如,我使用 api.bitbucket.org 而不是 bitbucket。org/api/ 来设置部署密钥) .

如果我尝试使用 curl 来实现,如:

curl -X POST -u user:pass https://api.bitbucket.org/1.0/repositories/repowner/reposlug/services/ --data "type=POST&URL=https://hooks.urladdress.com"

那就行了。但是尝试通过 python-requests 像在另一个 api 调用中那样进行操作将失败...

有人知道发生了什么事吗?它只会响应找不到资源,这似乎不正确(因为它通过 curl 工作)

找到 this 个问题非常相似的问题,但那里没有答案...

为了将来参考,其他人也有同样的问题,显然这个特定端点不接受 json 编码数据。

所以请求需要

requests.post(request_url, auth=(repo_user, repo_pass), data='type=POST&URL=hooks.url.com')