python-3.xnonetyperesponsetext

can only concatenate str (not "NoneType") to str


Having issues with get api response Text and Print it in python3

response = session.get(url=url, headers=headers, json=payload, verify=cabundle,
                               auth=auth)
        if response.status_code == 200:
            print(response.status_code)
            print("Response is:")
            data = json.loads(response.text)
            print(data)
            if data['issues']!= []:
                issueId = data['issues'][0]['id']
                print("Issue ID :    " +issueId)

Output:

200
Response is:
Expecting value: line 3 column 1 (char 4)
can only concatenate str (not "NoneType") to str

Can anyone help with this problem?


Solution

  • Check if the issueId exists before concatenating:

    issueId = data['issues'][0]['id']
    if issueId:
        print("Issue ID : " + issueId)