-2
def verify_app_log_cur_day2(self, anypoint_monitoring, organization_id, int, applist, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    payload = {}
    log_list = []
    for item in applist:
        url = f"{anypoint_monitoring}/organizations/{organization_id}/environments/{int}/applications/{item}/logs}"
        response = requests.request("GET", url, headers=headers, data=payload)
        if response.status_code == 503:
            continue
        else:
            log_list.append([response.json()])
    return log_list

How to add functionality to my code?

  • If response.status_code == 503 then try again
    • If response.status_code again == 503 then continue
Jim G.
  • 15,141
  • 22
  • 103
  • 166

1 Answers1

0

Simply do it this way

def verify_app_log_cur_day2(self, anypoint_monitoring, organization_id, int, applist, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    payload = {}
    log_list = []
    for item in applist:
        url = f"{anypoint_monitoring}/organizations/{organization_id}/environments/{int}/applications/{item}/logs}"
        response = requests.request("GET", url, headers=headers, data=payload)

        # Functionality:
        if response.status_code == 503:
            response = requests.request("GET", url, headers=headers, data=payload)
            if response.status_code == 503:
                continue                      
        else:
            log_list.append(response.json())

    return log_list
Jiya
  • 745
  • 8
  • 19