Azure-cli: Error running az apim command

Created on 10 Sep 2019  路  16Comments  路  Source: Azure/azure-cli

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az apim show

Errors:

No module named 'azure.mgmt.apimanagement.models.api_management_client_enums'
Traceback (most recent call last):
pip-install-qxmmnr17\knack\knack\cli.py, ln 206, in invoke
cli\core\commands\__init__.py, ln 523, in execute
azure\cli\core\__init__.py, ln 291, in load_arguments
cli\core\commands\__init__.py, ln 290, in load_arguments
pip-install-qxmmnr17\knack\knack\commands.py, ln 97, in load_arguments
cli\core\commands\arm.py, ln 709, in generic_show_arguments_loader
...
<frozen importlib._bootstrap_external>, ln 678, in exec_module
<frozen importlib._bootstrap>, ln 219, in _call_with_frames_removed
cli\command_modules\apim\custom.py, ln 9, in <module>
ModuleNotFoundError: No module named 'azure.mgmt.apimanagement.models.api_management_client_enums'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • _Put any pre-requisite steps here..._
  • az apim show

Expected Behavior

Environment Summary

Windows-10-10.0.18975-SP0
Python 3.6.6
Shell: powershell.exe

azure-cli 2.0.72
azure-cli-iot-ext 0.7.1

Extensions:
alias 0.5.2
azure-cli-iot-ext 0.7.1
azure-devops 0.12.0
interactive 0.4.3
storage-preview 0.2.7
vm-repair 0.1.1
webapp 0.2.19

Additional Context


API Management Service Attention

Most helpful comment

The custom.py file seems to reference a file called azure\mgmt\apimanagement\models\api_management_client_enums.py however if we look in the azure\mgmt\apimanagement\models directory we see that the file is actually called _api_management_client_enums.py.

Removing the underscore in the filename seems to work. But in order to not break anything else I advice you to copy the file and remove the underscore from the copy, so that programs that reference the file with the underscore don't break.

Disclaimer: I'm not familiar with the source, but this is a work around until it is officially fixed. I wouldn't use this in any production environment.

@ the azure team,
In the custom.py file, shouldn't the line

from azure.mgmt.apimanagement.models.api_management_client_enums import VirtualNetworkType, SkuType

just be

from azure.mgmt.apimanagement.models import VirtualNetworkType, SkuType

?
Those two classes are already exposed by the init file.

All 16 comments

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @mjconnection

I'm getting the same error. My version info:

> azure-cli                         2.0.73
> 
> command-modules-nspkg               2.0.3
> core                              2.0.73
> nspkg                              3.0.4
> telemetry                          1.0.3
> 
> Extensions:
> application-insights               0.1.1
> 
> Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
> Extensions directory 'C:\Users\MarcDuiker\.azure\cliextensions'
> 
> Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]
> 
> Legal docs and information: aka.ms/AzureCliLegal
> 
> 
> Your CLI is up-to-date.

I'm getting the same error. My version info:

> azure-cli                         2.0.73
> 
> command-modules-nspkg               2.0.3
> core                              2.0.73
> nspkg                              3.0.4
> telemetry                          1.0.3
> 
> Extensions:
> application-insights               0.1.1
> 
> Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
> Extensions directory 'C:\Users\MarcDuiker\.azure\cliextensions'
> 
> Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]
> 
> Legal docs and information: aka.ms/AzureCliLegal
> 
> 
> Your CLI is up-to-date.

Yes, I just updated my az cli to 2.0.73 and am still receiving the same error

The custom.py file seems to reference a file called azure\mgmt\apimanagement\models\api_management_client_enums.py however if we look in the azure\mgmt\apimanagement\models directory we see that the file is actually called _api_management_client_enums.py.

Removing the underscore in the filename seems to work. But in order to not break anything else I advice you to copy the file and remove the underscore from the copy, so that programs that reference the file with the underscore don't break.

Disclaimer: I'm not familiar with the source, but this is a work around until it is officially fixed. I wouldn't use this in any production environment.

@ the azure team,
In the custom.py file, shouldn't the line

from azure.mgmt.apimanagement.models.api_management_client_enums import VirtualNetworkType, SkuType

just be

from azure.mgmt.apimanagement.models import VirtualNetworkType, SkuType

?
Those two classes are already exposed by the init file.

@jurgyy ,

I can't find a file called custom.py in my machine. Where do you find it?

Mine is referring to a path where it is not there at all. This user doesn't exist C:\Users\VSSADM~1

az apim show
The command failed with an unexpected error. Here is the traceback:

No module named 'azure.mgmt.apimanagement.models.api_management_client_enums'
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\knack\knack\cli.py", line 206, in invoke
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\__init__.py", line 291, in load_arguments
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\commands\__init__.py", line 291, in load_arguments
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\knack\knack\commands.py", line 97, in load_arguments
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\commands\arm.py", line 709, in generic_show_arguments_loader
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\commands\arm.py", line 390, in get_arguments_loader
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli-core\azure\cli\core\__init__.py", line 528, in get_op_handler
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-6e754znd\azure-cli\azure\cli\command_modules\apim\custom.py", line 9, in <module>
ModuleNotFoundError: No module named 'azure.mgmt.apimanagement.models.api_management_client_enums'

@wshamroukh I don't think you should edit the custom.pyc file, since it's a compiled python file, but it's file location for me is is C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\command_modules\apim\.

For the work-around you can find the api_management_client_enums file in C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\mgmt\apimanagement\models\

@wshamroukh I don't think you should edit the custom.pyc file, since it's a compiled python file, but it's file location for me is is C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\command_modules\apim\.

For the work-around you can find the api_management_client_enums file in C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\mgmt\apimanagement\models\

For me not to get it working i had to have two files with the following names under C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\mgmt\apimanagement\models\:

api_management_client_enums.py
_api_management_client_enums.py

Because when I renamed the file from _api_management_client_enums.py to api_management_client_enums.py the __init__.py was still looking for _api_management_client_enums.py

Great that it works, but that's exactly what I said in my earlier comment ;)

But in order to not break anything else I advice you to copy the file and remove the underscore from the copy, so that programs that reference the file with the underscore don't break.

When should we expect a fix for this issue?

@MyronFanQiu has accepted my PR and has since been moved to the release branch, right? So this issue could be marked as solved.

@jurgyy Yes. It's has been released. Feel free to re-open this one if you still meet problems.

Same issue:
azure-cli 2.0.80

command-modules-nspkg 2.0.3
core 2.0.80
nspkg 3.0.4
telemetry 1.0.4

Used workaround above:
api_management_client_enums.py
_api_management_client_enums.py

This should be re-opened, it is still an issue with the latest release. The cloud powershell shell does not seem to be affected.

@Ugenx I have open a PR to fix it. @jurgyy Hi. Looks like last time we didn't fix them all. I have created a PR, could you please review it and sign off?

Yea, same as @Ugenx I'm still seeing this error in 2.1.0. You can reproduce it with any of the following commands:

  • az apim apply-network-updates --help
  • az apim backup --help
  • az apim check-name --help
  • az apim create --help
  • az apim delete --help
  • az apim list --help
  • az apim show --help
  • az apim update --help

@lprichar Sure. We have fixed this one and merged a PR. The new version will be available in the next week. Currently, you can use our edge build version. https://github.com/Azure/azure-cli#edge-builds

Was this page helpful?
0 / 5 - 0 ratings