Skip to content

Command not working anymore within python script, but still working with cli #20464

Description

@mcomisso-elux

Describe the bug

Command Name
az network vnet list

Errors:

The credential data used by CLI has been expired because you might have changed or reset the password. Please clear browser's cookies and run 'az login'

To Reproduce:

Script to reproduce the behavior.

#!/usr/bin/python3
from azure.cli.core import get_default_cli

def azurer(args_str):
    args = args_str.split()
    cli = get_default_cli()
    cli.invoke(args)
    return cli.result.result

subscriptions = azurer("account list")
for s in subscriptions:
    vnets = azurer("network vnet list --subscription " + s['name'])
    if type(vnets) == dict:
        for v in vnets:
            print(v['name'])

Expected Behavior

Last time I used this script (some weeks ago) it was working fine.
Also, the same command (network vnet list --subscription xxxxxx) executed from the CLI is still working fine.

Environment Summary

Linux-4.4.0-19041-Microsoft-x86_64-with-debian-bullseye-sid, Ubuntu 20.04.3 LTS
Python 3.6.10
Installer: DEB

azure-cli 2.30.0

Additional Context

I've cleared my account (az account clear) and tried again, same result. I've also tried with this environment:

Windows-10-10.0.19041-SP0, 
Python 3.9.4
Installer: PIP

azure-cli 2.30.0

obtaining this output:

User xxxxxxxxxxxxxxx does not exist in MSAL token cache. Run `az login`.

Metadata

Metadata

Labels

Networkaz network vnet/lb/nic/dns/etc...customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions