0

So I’m having some difficulty with my code. The code works but for some reason it only post one string instead of having all the strings posted in Jira. for example, up to the point that you see the #print(username, response), in the terminal I see all responses being printed in on screen. So it works great up to that point but the moment I send the same variable such as response through the Jira Dictionary called issue_dict, it creates the Jira but with only one of the responses and not all. I’ve tried doing something like response[x] but it just gives me an error that string indices must be integers. I’m not quite sure what else to do to be able to iterate through this so I can post all the results in the Description/body of a Jira ticket.

Ideally I would love to have both the user and the response in the description part. I’ve tried to do this with a List but I seem to get the same results where only one string gets printed. Anyone have done anything similar to post results in Jira?

Here is the code:

import jira from JIRA

for i in range(1,3):

        user = os.getenv(‘USER’ + str(i))
        pass = os.getenv(‘PASS’+ str(i))
        headers = {
            'X-Requested-With': 'Curl',
             }
        response =requests post('https://API-Address', headers=headers, auth=(USER,PASS))

         root = ET.fromString(response.text) # Parses the JSON into text

         for x in root.iter(’text’): #all this is doing is iterating through the file root and finding the text and saving the substring in response.
            response = x[2].text

            #print(username, response)
            issue_dict = {
            'project': {'id': 123},
            'summary’:’My Jira Using Py',   
            'description': response,  #This is the current issue!
            'issuetype': {'name': 'Bug'},
            }
new_issue = jira.create_issue(fields=issue_dict)
2
  • It's not clear to me why you're using elementtree (ET) on a json element. you should get your response in the right format with response.json()
    – Tranbi
    Commented Jun 28, 2022 at 8:58
  • I’ve used ET to parse the json and find the correct element within the json.Didn’t know if you can do that with response.json()
    – Manik
    Commented Jun 28, 2022 at 11:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.