Home > Software engineering >  Retry if status_code is 503
Retry if status_code is 503

Time:12-02

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

CodePudding user response:

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
  • Related