Command not working anymore within python script, but still working with cli
See original GitHub issueDescribe 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`.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Python script won't run from the command line. It shows no error
If you have Python in PATH but script execution still doesn't work, inspect the C:\Users<user>\AppData\Local\Microsoft\WindowsApps folder.
Read more >python script does not run from commandline
hello,. I'm having problems suddenly running .py scripts from the command line. (CMD). Before, *.py was associated with python.exe (The ...
Read more >-bash: python: command not found error and solution - nixCraft
This error means Python is either not installed or your installation damaged including wrong $PATH settings.. Here is how you can solve this ......
Read more >Python is not recognized as an internal or external command
One way to fix the error would be to launch Python from the Command Prompt by passing in the full path to the...
Read more >Troubleshooting Common Python Problems - IONOS
If you get a "permission denied" error when you attempt to run this Python script from the command line, most likely the permissions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot @jiasli, I’ve been able to solve the issue!
Regards, Matteo
This is because the Python script and direct
az network vnet list
command are calling different versions of Azure CLI.The error message
The credential data used by CLI ...
has long been removed by #17072. Please make sure the correct version of Azure CLI is called by upgrading to the latest versionBy the way, your script uses subscription name as
--subscription
which may break if there are spaces in it. You can use either subscription ID ofshlex.split
.Use subscription ID:
Use
shlex.split
: