Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
82 stars 65 forks source link

az iot central app monitor-events 400 Client Error: Bad Request for url #135

Closed NSannala closed 4 years ago

NSannala commented 4 years ago

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name az iot central app monitor-events Extension Name: azure-cli-iot-ext. Version: 0.8.8.

Errors:

400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token
Traceback (most recent call last):
python3.6/site-packages/knack/cli.py, ln 206, in invoke
    cmd_result = self.invocation.execute(args)
cli/core/commands/__init__.py, ln 608, in execute
    raise ex
cli/core/commands/__init__.py, ln 666, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
...
python3.6/site-packages/requests/models.py, ln 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token

To Reproduce:

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

Expected Behavior

Environment Summary

Linux-4.15.0-1066-azure-x86_64-with-debian-stretch-sid
Python 3.6.5
Shell: bash

azure-cli 2.0.80
azure-cli-iot-ext 0.8.8

Extensions:
azure-cli-iot-ext 0.8.8

Additional Context

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

400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 608, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 666, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job six.reraise(sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 636, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 306, in call return self.handler(args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 493, in default_command_handler return op(command_args) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/central.py", line 41, in iot_central_monitor_events eventHubTarget = builders.EventTargetBuilder().build_central_event_hub_target(cmd, app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 30, in build_central_event_hub_target return self.eventLoop.run_until_complete(self._build_central_event_hub_target_async(cmd, app_id, central_api_uri)) File "/opt/az/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete return future.result() File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 81, in _build_central_event_hub_target_async tokens = get_iot_central_tokens(cmd, app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 250, in get_iot_central_tokens aad_token = _get_aad_token(cmd, resource="https://apps.azureiotcentral.com")['accessToken'] File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 22, in _get_aad_token creds, subscription, tenant = profile.get_raw_token(subscription=None, resource=resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 603, in get_raw_token creds = self._get_token_from_cloud_shell(resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 376, in _get_token_from_cloud_shell auth = MSIAuthentication(resource=resource) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 592, in init self.set_token() File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 598, in settoken self.scheme, , self.token = get_msi_token(self.resource, self.port, self.msi_conf) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 486, in get_msi_token result.raise_for_status() File "/opt/az/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token

Jackbk commented 4 years ago

Hi @NSannala ,

Could you please provide the properties you are using for this request?

Thanks, Jack

NSannala commented 4 years ago

Both these commands return error

nishitha@Azure:~$az --version azure-cli 2.0.80

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

Extensions: azure-cli-iot-ext 0.8.8

Python location '/opt/az/bin/python3' Extensions directory '/home/nishitha/.azure/cliextensions'

Python (Linux) 3.6.5 (default, Jan 13 2020, 05:03:40) [GCC 5.4.0 20160609]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Please let us know how we are doing: https://aka.ms/clihats nishitha@Azure:~$az extension list-available --output table Name Version Summary Preview Installed


aem 0.1.1 Manage Azure Enhanced Monitoring Extensions for SAP False False aks-preview 0.4.27 Provides a preview for upcoming AKS features True False alias 0.5.2 Support for command aliases True False appconfig 0.5.0 Provides a preview for upcoming App Configuration features. True False application-insights 0.1.2 Support for managing Application Insights components and querying metrics, events, and logs from such components. True False azure-batch-cli-extensions 5.0.0 Additional commands for working with Azure Batch service False False azure-cli-iot-ext 0.8.8 The Azure IoT extension for Azure CLI. False True azure-cli-ml 1.0.85 Microsoft Azure Command-Line Tools AzureML Command Module False False azure-devops 0.17.0 Tools for managing Azure DevOps. False False azure-firewall 0.1.8 Manage Azure Firewall resources. True False connectedmachine 0.1.0 Microsoft Azure Command-Line Tools Connectedmachine Extension True False db-up 0.1.13 Additional commands to simplify Azure Database workflows. True False dev-spaces 1.0.4 Dev Spaces provides a rapid, iterative Kubernetes development experience for teams. False False dms-preview 0.9.0 Support for new Database Migration Service scenarios. True False eventgrid 0.4.4 Microsoft Azure Command-Line Tools EventGrid Command Module. True False express-route 0.1.3 Manage ExpressRoutes with preview features. True False express-route-cross-connection 0.1.1 Manage customer ExpressRoute circuits using an ExpressRoute cross-connection. False False find 0.3.0 Intelligent querying for CLI information. True False front-door 1.0.2 Manage networking Front Doors. False False hack 0.4.1 Microsoft Azure Command-Line Tools Hack Extension True False healthcareapis 0.1.2 Microsoft Azure Command-Line Tools HealthCareApis Extension False False image-copy-extension 0.2.3 Support for copying managed vm images between regions False False interactive 0.4.3 Microsoft Azure Command-Line Interactive Shell True False internet-analyzer 0.1.0rc4 Microsoft Azure Command-Line Tools Internet Analyzer Extension True False ip-group 0.1.0 Microsoft Azure Command-Line Tools IpGroup Extension False False keyvault-preview 0.1.3 Preview Azure Key Vault commands. True False log-analytics 0.1.4 Support for Azure Log Analytics query capabilities. True False maintenance 1.0.0 Support for Azure maintenance management preview. True False managementgroups 0.1.0 An Azure CLI Extension for Management Groups False False managementpartner 0.1.2 Support for Management Partner preview False False mesh 0.10.6 Support for Microsoft Azure Service Fabric Mesh - Public Preview True False mixed-reality 0.0.1 Mixed Reality Azure CLI Extension. False False netappfiles-preview 0.3.2 Provides a preview for upcoming Azure NetApp Files (ANF) features. True False peering 0.1.0rc1 Microsoft Azure Command-Line Tools Peering Extension True False privatedns 0.1.1 Commands to manage Private DNS Zones True False resource-graph 1.0.0 Support for querying Azure resources with Resource Graph. False False sap-hana 0.5.5 Additional commands for working with SAP HanaOnAzure instances. False False spring-cloud 0.2.0 Microsoft Azure Command-Line Tools spring-cloud Extension True False storage-preview 0.2.10 Provides a preview for upcoming storage features. True False subscription 0.1.3 Support for subscription management preview. False False virtual-network-tap 0.1.0 Manage virtual network taps (VTAP). True False virtual-wan 0.1.2 Manage virtual WAN, hubs, VPN gateways and VPN sites. True False vm-repair 0.2.4 Auto repair commands to fix VMs. False False vmware-cs 0.2.0 Manage Azure VMware Solution. True False webapp 0.2.24 Additional commands for Azure AppService. True False nishitha@Azure:~$az iot central app monitor-events --app-id 0c80793f-db9e-4c45-959a-46accee49365 --properties all The command failed with an unexpected error. Here is the traceback:

400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 608, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 666, in _run_jobs_serially results.append(self._run_job(expanded_arg,cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job six.reraise(sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, inreraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 636, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 306, in call return self.handler(args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 493, indefault_command_handler return op(command_args) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/central.py", line 41, iniot_central_monitor_events eventHubTarget = builders.EventTargetBuilder().build_central_event_hub_target(cmd,app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 30, inbuild_central_event_hub_target return self.eventLoop.run_until_complete(self._build_central_event_hub_target_async(cmd,app_id, central_api_uri)) File "/opt/az/lib/python3.6/asyncio/base_events.py", line 468, inrun_until_complete return future.result() File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 81, in _build_central_event_hub_target_async tokens = get_iot_central_tokens(cmd,app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 250, inget_iot_central_tokens aad_token = _get_aad_token(cmd, resource="https://apps.azureiotcentral.com")['accessToken'] File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 22, in _get_aad_token creds, subscription, tenant = profile.get_raw_token(subscription=None, resource=resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 603, inget_raw_token creds = self._get_token_from_cloud_shell(resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 376, in _get_token_from_cloud_shell auth = MSIAuthentication(resource=resource) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 592, in init self.set_token() File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 598, insettoken self.scheme, , self.token =get_msi_token(self.resource,self.port, self.msi_conf) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 486, inget_msi_token result.raise_for_status() File "/opt/az/lib/python3.6/site-packages/requests/models.py", line 940, inraise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token

To open an issue, please run: 'az feedback' nishitha@Azure:~$az iot central app monitor-events --app-id 0c80793f-db9e-4c45-959a-46accee49365 The command failed with an unexpected error. Here is the traceback:

400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 608, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 666, in _run_jobs_serially results.append(self._run_job(expanded_arg,cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job six.reraise(sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, inreraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 636, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 306, in call return self.handler(args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 493, indefault_command_handler return op(command_args) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/central.py", line 41, iniot_central_monitor_events eventHubTarget = builders.EventTargetBuilder().build_central_event_hub_target(cmd,app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 30, inbuild_central_event_hub_target return self.eventLoop.run_until_complete(self._build_central_event_hub_target_async(cmd,app_id, central_api_uri)) File "/opt/az/lib/python3.6/asyncio/base_events.py", line 468, inrun_until_complete return future.result() File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/operations/events3/_builders.py", line 81, in _build_central_event_hub_target_async tokens = get_iot_central_tokens(cmd,app_id, central_api_uri) File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 250, inget_iot_central_tokens aad_token = _get_aad_token(cmd, resource="https://apps.azureiotcentral.com")['accessToken'] File "/home/nishitha/.azure/cliextensions/azure-cli-iot-ext/azext_iot/common/_azure.py", line 22, in _get_aad_token creds, subscription, tenant = profile.get_raw_token(subscription=None, resource=resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 603, inget_raw_token creds = self._get_token_from_cloud_shell(resource) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 376, in _get_token_from_cloud_shell auth = MSIAuthentication(resource=resource) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 592, in init self.set_token() File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 598, insettoken self.scheme, , self.token =get_msi_token(self.resource,self.port, self.msi_conf) File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 486, inget_msi_token result.raise_for_status() File "/opt/az/lib/python3.6/site-packages/requests/models.py", line 940, inraise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:50342/oauth2/token

To open an issue, please run: 'az feedback' From: Jack Barker notifications@github.com Sent: Thursday, January 23, 2020 4:57 PM To: Azure/azure-iot-cli-extension azure-iot-cli-extension@noreply.github.com Cc: Nishitha Sannala nsannala@microsoft.com; Mention mention@noreply.github.com Subject: Re: [Azure/azure-iot-cli-extension] az iot central app monitor-events 400 Client Error: Bad Request for url (#135)

Hi @NSannalahttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FNSannala&data=02%7C01%7Cnsannala%40microsoft.com%7Ccbe8595b7e34437a588c08d7a06856c6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637154242310825599&sdata=%2FfLUmaIAzg9dAZC%2F848vDZAaRxmhUj4GETkndOGogj0%3D&reserved=0 ,

Could you please provide the properties you are using for this request?

Thanks, Jack

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-iot-cli-extension%2Fissues%2F135%3Femail_source%3Dnotifications%26email_token%3DAB6ZVQXMTC7LXZNAXGWQQILQ7I4GJA5CNFSM4KK4DLU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJZMQVQ%23issuecomment-577947734&data=02%7C01%7Cnsannala%40microsoft.com%7Ccbe8595b7e34437a588c08d7a06856c6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637154242310825599&sdata=MymsC%2FiydWM%2FthCGrNdipoutKviaaGiPb8xsqsXjyaE%3D&reserved=0, orunsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAB6ZVQSNRTKFP4PAJGDA4T3Q7I4GJANCNFSM4KK4DLUQ&data=02%7C01%7Cnsannala%40microsoft.com%7Ccbe8595b7e34437a588c08d7a06856c6%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637154242310835551&sdata=dLNNBz3EOWVH0PiLQTJ3Bhms%2FwuIXKAIkSEXubt4wpU%3D&reserved=0.

Jackbk commented 4 years ago

Hi @NSannala ,

Could you please try and run the "az login" command before running monitor-events? I believe this error shows in cloud shell when the user has not logged in yet.

Regards, Jack

NSannala commented 4 years ago

Thanks for the tip. That worked. Not clear why other commands like az iot hub monitor-events was working but not az iot central.

From: Jack Barker notifications@github.com Sent: Monday, January 27, 2020 12:14 PM To: Azure/azure-iot-cli-extension azure-iot-cli-extension@noreply.github.com Cc: Nishitha Sannala nsannala@microsoft.com; Mention mention@noreply.github.com Subject: Re: [Azure/azure-iot-cli-extension] az iot central app monitor-events 400 Client Error: Bad Request for url (#135)

Hi @NSannalahttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FNSannala&data=02%7C01%7Cnsannala%40microsoft.com%7Cca70e3178130408f576c08d7a3657292%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637157528423176565&sdata=mxasAMUFVMI7O2%2FO4M6fQu0nGA2SHO2liHrBna5%2FHtg%3D&reserved=0 ,

Could you please try and run the "az login" command before running monitor-events? I believe this error shows in cloud shell when the user has not logged in yet.

Regards, Jack

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-iot-cli-extension%2Fissues%2F135%3Femail_source%3Dnotifications%26email_token%3DAB6ZVQQJEIUGVTPJEVSNQXDQ746APA5CNFSM4KK4DLU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKA4UVY%23issuecomment-578931287&data=02%7C01%7Cnsannala%40microsoft.com%7Cca70e3178130408f576c08d7a3657292%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637157528423176565&sdata=HtwD14YxK19G1oywXQFrFVM9rf8U2DbltU%2Fvz%2BGHvE4%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAB6ZVQUFTIUAKZVYGOF4XM3Q746APANCNFSM4KK4DLUQ&data=02%7C01%7Cnsannala%40microsoft.com%7Cca70e3178130408f576c08d7a3657292%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637157528423186551&sdata=xVjSmmyTZZvBIxIjXs0vC%2FPgBzXnBrEmzZhsPpQZHYw%3D&reserved=0.

Jackbk commented 4 years ago

I'm glad you got it working. I'm looking into this further, as a more descriptive error is shown from a local shell, but this one is shown in the cloud shell.