I want part in except block to be executed if error faced in try block, error is raised if customfield_10005
has incorrect value, so i purposely set wrong value for customfile_10005 but again except block is not executed, what's wrong with this code ?
customfile_10005 is JIRA Epic ID and i want not to raise errors if that ID is wrong:
from jira import JIRA
from jira.exceptions import JIRAError
try: headers = {"Content-Type": "application/json"} data = {"fields":{"project":{"key":"CP"},"issuetype":{"name":"Task"},"reporter":{"name":reporter},"assignee":{"name":reporter},
"summary":"Pre-Sales - Placeholder - 1/5 {this_month} - {reporter}".format(**locals()),
"description":"descriptions",
"customfield_10107":{"id":"10400"},
"customfield_11300":{"value":"Engineering"},
"customfield_11301":{"value":"York"},
"customfield_10005":200
}} response = requests.post('https://jira.company.com/rest/api/latest/issue/', data = json.dumps(data),auth=('user', password), headers= headers)
print (response.content)
except JIRAError as e:
print ("some errors")
Instead of "some errors" i specified, i'm getting default error message
b'{"errorMessages":["Issue can be assigned only active or future sprints."],"errors":{}}''
I used response output to create "error handler" (because exception block doesn't work), if in response output there is string errorMessages
, run "exception block"
headers = {"Content-Type": "application/json"}
data = {"fields":{"project":{"key":"CP"},"issuetype":{"name":"Task"},"reporter":{"name":reporter},"assignee":{"name":reporter},
"summary":"Pre-Sales - Placeholder - 1/5 {this_month} - {reporter}".format(**locals()),
"description":"descriptions",
"customfield_10107":{"id":"10400"},
"customfield_11300":{"value":"Engineering"},
"customfield_11301":{"value":"York"},
"customfield_10005":200}}
response = requests.post('https://jira.company.com/rest/api/latest/issue/', data = json.dumps(data),auth=('user', password), headers= headers)
print(response.content)
out = response.content
if b'errorMessages' in out:
headers = {"Content-Type": "application/json"}
data = {"fields":{"project":{"key":"CP"},"issuetype": {"name":"Task"},"reporter":{"name":reporter},"assignee":{"name":reporter},
"summary":"Pre-Sales - Placeholder - 1/5 {this_month} - {reporter}".format(**locals()),
"description":description",
"customfield_10107":{"id":"10400"},
"customfield_11300":{"value":"Engineering"},
"customfield_11301":{"value":"York"}
}}
response = requests.post('https://jira.company.com/rest/api/latest/issue/', data = json.dumps(data),auth=('user', password), headers= headers)
print (response.content)
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.