# Buggy code
def _check_zip_deployment_status(deployment_status_url, authorization):
    import requests
    import time

    num_trials = 1
    while num_trials < 10:
        time.sleep(15)
        response = requests.get(deployment_status_url, headers=authorization)
        res_dict = response.json()
        num_trials = num_trials + 1
        if res_dict["status"] == 5:
            logger.warning("Zip deployment failed status %s", res_dict["status_text"])
            break
        elif res_dict["status"] == 4:
            break
        logger.info(
            res_dict["progress"]
        )  # show only in debug mode, customers seem to find this confusing
    # if the deployment is taking longer than expected
    if res_dict["status"] != 4:
        logger.warning(
            """Deployment is taking longer than expected. Please verify status at '%s'
            beforing launching the app""",
            deployment_status_url,
        )
    return res_dict


# Traceback (KeyError)
'status'
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 373, in execute
six.reraise(*sys.exc_info())
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 347, in execute
result = cmd(params)
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/core/commands/__init__.py", line 182, in __call__
return self.handler(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/core/__init__.py", line 440, in default_command_handler
result = op(**command_args)
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/command_modules/appservice/custom.py", line 265, in enable_zip_deploy
response = _check_zip_deployment_status(deployment_status_url, authorization)
File "/usr/local/Cellar/azure-cli/2.0.50/libexec/lib/python3.7/site-packages/azure/cli/command_modules/appservice/custom.py", line 1986, in _check_zip_deployment_status
if res_dict['status'] == 5:
KeyError: 'status'

# Fixed code
def _check_zip_deployment_status(deployment_status_url, authorization):
    import requests
    import time

    num_trials = 1
    while num_trials < 10:
        time.sleep(15)
        response = requests.get(deployment_status_url, headers=authorization)
        res_dict = response.json()
        num_trials = num_trials + 1
        if res_dict.get("status", 0) == 5:
            logger.warning("Zip deployment failed status %s", res_dict["status_text"])
            break
        elif res_dict.get("status", 0) == 4:
            break
        if "progress" in res_dict:
            logger.info(
                res_dict["progress"]
            )  # show only in debug mode, customers seem to find this confusing
    # if the deployment is taking longer than expected
    if res_dict.get("status", 0) != 4:
        logger.warning(
            """Deployment is taking longer than expected. Please verify status at '%s'
            beforing launching the app""",
            deployment_status_url,
        )
    return res_dict