I am using python requests to update the status of a Jira ticket. Below is the code -
headers = {"Content-type": "application/json",'Accept' : 'application/json'}
body = {"update": {"comment": [{"add": {"body": "The ticket is resolved"}}]},"transition": {"id":id }}
url = f"http://jira.domain.com:8080/rest/api/2/issue/{key}/transitions"
r = requests.post(url,data=body,auth=HTTPBasicAuth('user', 'password'),headers=headers)
the value of key is correct. The value of transition id is correct. When I trigger the same post request through postman, Jira gets updated. However when executing it through python script, I get the following error -
{"errorMessages":["Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@3bb9f13b; line: 1, column: 2]"]}
Please let me know, how to resolve the error.
The issue has been resolved.
The request documentation says -
Instead of encoding the
dict
yourself, you can also pass it directly using thejson
parameter (added in version 2.4.2) and it will be encoded automatically:
I changed the post request. instead of data=body, I made it json=body
r = requests.post(url,json=body,auth=HTTPBasicAuth('XXX', 'YYY'),headers=headers)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above hint solved my issue too :-)Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tushar
I believe that you need a closing bracket and comma before comment, then remove the extra bracket before transition, so
body = {"update":{}, "comment":[{ "add": { "body": "The ticket is resolved"}}],"transition": { "id": id }}
is valid JSON and is a similar structure to what I use
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Warren If I use your syntax, I am still getting the error. The error message is -
"Unexpected character ('c' (code 99)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@66c7db85; line: 1, column: 2]"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.