# Buggy code
def _get_credentials(
    cli_ctx,
    registry_name,
    resource_group_name,
    username,
    password,
    only_refresh_token,
    repository=None,
    permission="*",
):
    """Try to get AAD authorization tokens or admin user credentials.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    :param str username: The username used to log into the container registry
    :param str password: The password used to log into the container registry
    :param bool only_refresh_token: Whether to ask for only refresh token, or for both refresh and access tokens
    :param str repository: Repository for which the access token is requested
    :param str permission: The requested permission on the repository, '*' or 'pull'
    """
    registry, _ = get_registry_by_name(cli_ctx, registry_name, resource_group_name)
    login_server = registry.login_server

    # 1. if username was specified, verify that password was also specified
    if username:
        if not password:
            try:
                password = prompt_pass(msg="Password: ")
            except NoTTYException:
                raise CLIError(
                    "Please specify both username and password in non-interactive mode."
                )

        return login_server, username, password

    # 2. if we don't yet have credentials, attempt to get a refresh token
    if not password and registry.sku.name in MANAGED_REGISTRY_SKU:
        try:
            username = (
                "00000000-0000-0000-0000-000000000000" if only_refresh_token else None
            )
            password = _get_aad_token(
                login_server, only_refresh_token, repository, permission
            )
            return login_server, username, password
        except CLIError as e:
            logger.warning(
                "Unable to get AAD authorization tokens with message: %s", str(e)
            )

    # 3. if we still don't have credentials, attempt to get the admin credentials (if enabled)
    if not password:
        try:
            client = cf_acr_registries(cli_ctx)
            cred = get_acr_credentials(cli_ctx, client, registry_name)
            username = cred.username
            password = cred.passwords[0].value
            return login_server, username, password
        except CLIError as e:
            logger.warning(
                "Unable to get admin user credentials with message: %s", str(e)
            )

    # 4. if we still don't have credentials, prompt the user
    if not password:
        try:
            username = prompt("Username: ")
            password = prompt_pass(msg="Password: ")
            return login_server, username, password
        except NoTTYException:
            raise CLIError(
                "Unable to authenticate using AAD or admin login credentials. "
                + "Please specify both username and password in non-interactive mode."
            )


# Traceback (AttributeError)
C:\Users\marsma>az acr login --name acr604
'bool' object has no attribute 'rstrip'
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\knack\cli.py", line 193, in invoke
cmd_result = self.invocation.execute(args)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 319, in execute
six.reraise(*sys.exc_info())
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 292, in execute
result = cmd(params)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 169, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\knack\commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\__init__.py", line 328, in default_command_handler
result = op(**command_args)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\custom.py", line 195, in acr_login
password=password)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 194, in get_login_credentials
only_refresh_token=True)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 150, in _get_credentials
password = _get_aad_token(login_server, only_refresh_token, repository, permission)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 35, in _get_aad_token
login_server = login_server.rstrip('/')
AttributeError: 'bool' object has no attribute 'rstrip'

# Fixed code
def _get_credentials(
    cli_ctx,
    registry_name,
    resource_group_name,
    username,
    password,
    only_refresh_token,
    repository=None,
    permission="*",
):
    """Try to get AAD authorization tokens or admin user credentials.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    :param str username: The username used to log into the container registry
    :param str password: The password used to log into the container registry
    :param bool only_refresh_token: Whether to ask for only refresh token, or for both refresh and access tokens
    :param str repository: Repository for which the access token is requested
    :param str permission: The requested permission on the repository, '*' or 'pull'
    """
    registry, resource_group_name = get_registry_by_name(
        cli_ctx, registry_name, resource_group_name
    )
    login_server = registry.login_server

    # 1. if username was specified, verify that password was also specified
    if username:
        if not password:
            try:
                password = prompt_pass(msg="Password: ")
            except NoTTYException:
                raise CLIError(
                    "Please specify both username and password in non-interactive mode."
                )

        return login_server, username, password

    # 2. if we don't yet have credentials, attempt to get a refresh token
    if not password and registry.sku.name in MANAGED_REGISTRY_SKU:
        try:
            username = (
                "00000000-0000-0000-0000-000000000000" if only_refresh_token else None
            )
            password = _get_aad_token(
                cli_ctx, login_server, only_refresh_token, repository, permission
            )
            return login_server, username, password
        except CLIError as e:
            logger.warning(
                "Unable to get AAD authorization tokens with message: %s", str(e)
            )

    # 3. if we still don't have credentials, attempt to get the admin credentials (if enabled)
    if not password and registry.admin_user_enabled:
        try:
            cred = cf_acr_registries(cli_ctx).list_credentials(
                resource_group_name, registry_name
            )
            username = cred.username
            password = cred.passwords[0].value
            return login_server, username, password
        except CLIError as e:
            logger.warning(
                "Unable to get admin user credentials with message: %s", str(e)
            )

    # 4. if we still don't have credentials, prompt the user
    if not password:
        try:
            username = prompt("Username: ")
            password = prompt_pass(msg="Password: ")
            return login_server, username, password
        except NoTTYException:
            raise CLIError(
                "Unable to authenticate using AAD or admin login credentials. "
                + "Please specify both username and password in non-interactive mode."
            )