Dear team Bitbucket,
Using the API, specifically REST Resources Provided By: Bitbucket Server - REST
Here is the code I’m using
import requests as req, json, sys
from urllib3 import encode_multipart_formdata
try:
net_pol = open(sys.argv[1]).read()
except:
"Could not open the network policy file. Exiting."
sys.exit(1)
repo = sys.argv[2]
token = ""
branch = "netpol"
# print("net_pol file is:", net_pol,"repo is", repo)
payload = {'content': ("networkPolicy.yaml", net_pol), 'message': "Automatically synthesized policy using NP-Guard", "branch": branch, "sourceCommitId": ""}
data, boundary = encode_multipart_formdata(payload)
headers = {}
headers["Content-Type"] = boundary
headers["Authorization"] = f"Bearer {token}"
res = req.put(f"https://bitbucket.local:8443/projects/myproject/repos/{repo}/browse/helm-chart/templates/networkPolicy.yaml", data=data, headers=headers, verify=False)
if res.status_code != 201:
print("Could not upload the policy.")
print(res.request.body)
print(res.content)
sys.exit(1)
The server returns 405 for a POST request as well.
Similar to the issue 63377 from last year BUT I am using form data.
Please assist.
Thank you.