虽然这段代码可以很好地将部署ssh-key添加到我的repos ...
print 'Connecting to Bitbucket...'
bitbucket_access = base64.b64encode(userbb + ":" + passwordbb)
bitbucket_headers = {"Content-Type":"application/json", "Authorization":"Basic " + bitbucket_access}
bitbucket_request_url = "https://bitbucket.org/api/1.0/repositories/<username>/%s/deploy-keys" % project_name
bitbucket_request_req = urllib2.Request(bitbucket_request_url)
for key,value in bitbucket_headers.items():
bitbucket_request_req.add_header(key,value)
request_data = json.dumps({"key":public_key, "label":subproject})
request_response = urllib2.urlopen(bitbucket_request_req, request_data)
...我不能这样做来创建一个服务钩子。
print 'Connecting to Bitbucket...'
bitbucket_access = base64.b64encode(userbb + ":" + passwordbb)
bitbucket_headers = {"Content-Type":"application/json", "Authorization":"Basic " + bitbucket_access}
bitbucket_request_url = "https://bitbucket.org/api/1.0/repositories/<username>/%s/services" % project_name
bitbucket_request_req = urllib2.Request(bitbucket_request_url)
for key,value in bitbucket_headers.items():
bitbucket_request_req.add_header(key,value)
request_data = json.dumps({"type":"POST","URL":webhook})
request_response = urllib2.urlopen(bitbucket_request_req, request_data)
因为它给了我404
urllib2.HTTPError: HTTP Error 404: NOT FOUND
但我可以使用curl手动创建一个webhook:
curl -X POST -u ${USERNAME}:${PASSWORD} https://bitbucket.org/api/1.0/repositories/<username>/<repository>/services --data 'type=POST&URL=https%3A%2F%2Fmydomain.com%2Fwebhook'
那么我如何使用python urllib2在Bitbucket API中成功地将webhook URL添加到我的存储库?