I am trying to follow this example:
and I have modified my python code to this:
def create_comment(pr_id, comment):
url = f"http://{baseurl}/rest/api/latest/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pr_id}/comments"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
payload = json.dumps({"text": comment})
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
verify=False,
auth=HTTPKerberosAuth(mutual_authentication=OPTIONAL),
)
print(response.status_code)
print(
json.dumps(
json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
)
)
But as a response I always get:
400
{
"errors": [
{
"context": null,
"exceptionName": null,
"message": "The path query parameter is required when retrieving comments."
}
]
}
What am I doing wrong here? I am not trying to retrieve comments. I am trying to add a comment. I can add a ?path=/
to my url, but then I only get an empty list of comments.
Hey @Matthias Redies
I think the problem is with the python requests, which on redirect, transform the POST into a GET request.
My guess is that because you are using "http", you get a redirect (301 or 302) to "https", and then the method changes.
If that doesn't help, try adding allow_redirects=False to disable redirections from the server.
Hope that helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.