Skip to content

[WIP] Copilot Request#33578

Draft
Copilot wants to merge 1 commit into
devfrom
copilot/fix-6844498-51040886-d5a985b8-5525-4f45-aa00-1c07e6191887
Draft

[WIP] Copilot Request#33578
Copilot wants to merge 1 commit into
devfrom
copilot/fix-6844498-51040886-d5a985b8-5525-4f45-aa00-1c07e6191887

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>Inconsistencies in the way az rest parses ' and " between regular and interactive CLI</issue_title>
<issue_description>### Describe the bug

Hi all,

While investigating the following issue that I encountered with az consumption budget create: #29950
I came across a strange inconsistency in the way commands are parsed in the interactive CLI and the regular CLI. One commentor suggested a fix of using az rest and adjusting the body, and this kind of ended up fixing the issue.

Related command

The following command works in the interactive CLI but not the regular CLI. In the regular CLI, it throws an error (the az prefix is excluded in interactive mode).

az rest --method PUT --url 'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01' --body '{"properties":{"amount":10.0,"category":"cost","filter":{},"timeGrain":"monthly","timePeriod":{"endDate":"2027-01-01T05:00:00.000Z","startDate":"2026-06-01T04:00:00.000Z"}}}'

The error attached can be remedied if the user replaces all single quotes with double quotes and instead uses \" to escape double quotes within the command.

Errors

The command failed with an unexpected error. Here is the traceback:
No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 677, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 789, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 335, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 23, in rest_call
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1089, in send_raw_request
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 700, in send
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 795, in get_adapter
requests.exceptions.InvalidSchema: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"

Based on the traceback, the error seems to stem from the fact that the --url parameter is not parsed properly in the regular CLI, thus leading to a URL submitted between single quotes to remain underneath single quotes.

Issue script & Debug output

Debug output of the command that only works in the interactive CLI:

cli.knack.cli: Command arguments: ['rest', '--method', 'PUT', '--url', "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'", '--body', "'{properties:{amount:10.0,category:cost,filter:{},timeGrain:monthly,timePeriod:{endDate:2027-01-01T05:00:00.000Z,startDate:2026-06-01T04:00:00.000Z}}}'", '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x0165D528>, <function OutputProducer.on_global_arguments at 0x019A0618>, <function CLIQuery.on_global_arguments at 0x019C4898>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Using packaged command index for profile 'latest'.
cli.azure.cli.core: Found installed extension 'interactive' (azext_interactive).
cli.azure.cli.core: Modules found from index for 'rest': ['azure.cli.command_modules.util']
cli.azure.cli.core: Loading command modules...
cli.azure.cli.core: Loaded command modules in parallel:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: util                      0.007         1         3
cli.azure.cli.core: Total (1)                 0.011         1         3
cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
cli.azure.cli.core: Loading extensions:
cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
cli.azure.cli.core: Total (0)                 0.000         0         0
cli.azure.cli.core: Loaded 1 groups, 3 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : rest
cli.azure.cli.core: Command table: rest
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x01B52258>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\gensk\.azure\commands\2026-06-05.03-57-31.rest.31196.log'.
az_command_data_logger: command args: rest --method {} --url {} --body {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x01B828E8>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x01B82938>, <function register_global_policy_argument.<locals>.add_global_policy_argument at 0x01B82CF8>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x01B82D48>, <function register_upcoming_breaking_change_info.<locals>.update_breaking_change_info at 0x01B82D98>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x019A0668>, <function CLIQuery.handle_query_parameter at 0x019C48E8>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x01B82CA8>]
cli.azure.cli.core.util: Request URL: "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
cli.azure.cli.core.util: Request method: 'PUT'
cli.azure.cli.core.util: Request headers:
cli.azure.cli.core.util:     'User-Agent': 'python/3.13.13 (Windows-11-10.0.26220-SP0) AZURECLI/2.87.0 (MSI)'
cli.azure.cli.core.util:     'Accept-Encoding': 'gzip, deflate'
cli.azure.cli.core.util:     'Accept': '*/*'
cli.azure.cli.core.util:     'Connection': 'keep-alive'
cli.azure.cli.core.util:     'x-ms-client-request-id': '9c0a5743-48a0-405a-b2ce-814e767bb196'
cli.azure.cli.core.util:     'Content-Type': 'application/json'
cli.azure.cli.core.util:     'CommandName': 'rest'
cli.azure.cli.core.util:     'ParameterSetName': '--method --url --body --debug'
cli.azure.cli.core.util:     'Content-Length': '151'
cli.azure.cli.core.util: Request body:
cli.azure.cli.core.util: "{properties:{amount:10.0,category:cost,filter:{},timeGrain:monthly,timePeriod:{endDate:2027-01-01T05:00:00.000Z,startDate:2026-06-01T04:00:00.000Z}}}"
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 677, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 789, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 335, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 23, in rest_call
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1089, in send_raw_request
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 700, in send
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 795, in get_adapter
requests.exceptions.InvalidSchema: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 677, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 789, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 335, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 23, in rest_call
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1089, in send_raw_request
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 700, in send
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 795, in get_adapter
requests.exceptions.InvalidSchema: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
az_command_data_logger: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 677, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 789, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 335, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 23, in rest_call
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1089, in send_raw_request
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 700, in send
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\requests/sessions.py", line 795, in get_adapter
requests.exceptions.InvalidSchema: No connection adapters were found for "'https://management.azure.com/subscriptions/2a62e50d-4f3d-432d-8627-5acbe1680c8c/providers/Microsoft.Consumption/budgets/monthlyBudget?api-version=2023-05-01'"
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x01B52398>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 1.133 seconds (init: 0.181, invoke: 0.952)

Expected behavior

Expected behavior is to create a budget, however the command throws an error in some instances.

Environment Summary

azure-cli 2.87.0

core 2.87.0
telemetry 1.1.0

Extensions:
interactive 1.0.0b1

Dependencies:
msal 1.36.0
azure-mgmt-resource 24.0.0

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\gensk.azure'
Extensions directory 'C:\Users\gensk.azure\cliextensions'

Python (Windows) 3.13.13 (tags/v3.13.13:01104ce, Apr 7 2026, 19:11:29) [MSC v.1944 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

There seems to be a number of similar bugs that stem from strange parsing between single and double quotes; in the regular CLI, another one I found during this process involved wrapping only the --url in double quotes but leaving the --body in single quotes (with double quotes inside for the json). This led to the api request body in debug mode appearing as being entirely wrapped in double quotes (as in, double quotes AROUND the json object) and also having stripped all of the double quotes from inside of the json (which somehow led to an authorization error...?). I'm unsure if these are all related to one single parsing issue, but one step at a time :)</issue_description>

Comments on the Issue (you are @copilot in this section)

@yonzhan Thank you for opening this issue, we will look into it. @azclibot Thanks for the detailed report and the follow-up clarification!

Issue Summary:
On Windows cmd.exe, single quotes are treated as literal characters (unlike bash/zsh), so a command like:

az rest --method PUT --url 'https://...' --body '{...}'

passes the URL as 'https://...' (with literal single quotes) to the CLI. This causes az rest to fail with No connection adapters were found for "'https://...".

However, the interactive CLI (az interactive) strips the surrounding single quotes before parsing, making the same command work there — creating an inconsistency.

Root cause area: azure/cli/core/util.pysend_raw_request (or argument pre-processing in interactive mode via azext_interactive).

Suggested investigation:

  1. Check how az interactive pre-processes arguments before dispatching — it likely strips surrounding single quotes from values.
  2. Evaluate whether az rest (and possibly all commands) should normalize arguments that have mismatched/unnecessary surrounding single quotes on Windows, or at least emit a clear warning.
  3. Consider adding a user-friendly error message when the URL contains leading/trailing quotes (e.g., "It looks like your URL contains surrounding quotes — if you're using cmd.exe, replace single quotes with double quotes").

Repro environment: Windows 11, cmd.exe, Azure CLI 2.87.0 (MSI), az rest command.


Posted by agent-assist (autonomous bug-fix pipeline).</comment_new>

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 17, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
️✔️acs
️✔️latest
️✔️3.12
️✔️3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
️✔️apim
️✔️latest
️✔️3.12
️✔️3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️aro
️✔️latest
️✔️3.12
️✔️3.14
️✔️backup
️✔️latest
️✔️3.12
️✔️3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
️✔️billing
️✔️latest
️✔️3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.14
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.14
️✔️dls
️✔️latest
️✔️3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.14
️✔️identity
️✔️latest
️✔️3.12
️✔️3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️maps
️✔️latest
️✔️3.12
️✔️3.14
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.14
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.14
️✔️network
️✔️latest
️✔️3.12
️✔️3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
️✔️relay
️✔️latest
️✔️3.12
️✔️3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.14
️✔️storage
️✔️latest
️✔️3.12
️✔️3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
️✔️vm
️✔️latest
️✔️3.12
️✔️3.14

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 17, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@azclibot

Copy link
Copy Markdown
Collaborator

Live test results — azdev test util --live --series

FAIL (exit 1)

Target: util (module)
PR head ref: copilot/fix-6844498-51040886-d5a985b8-5525-4f45-aa00-1c07e6191887
PR head sha: 112e39b136790c2bc5e4c1f464e40580b55043e4
PR base ref: dev
New test files in PR: false

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/27671241511

Last 80 lines of azdev output
    
        result = {}
        for s in uri_parameters or []:
            try:
                temp = shell_safe_json_parse(s)
                result.update(temp)
            except CLIError:
                key, value = s.split('=', 1)
                result[key] = value
        uri_parameters = result or None
    
        endpoints = cli_ctx.cloud.endpoints
        # If url is an ARM resource ID, like /subscriptions/xxx/resourcegroups/xxx?api-version=2019-07-01,
        # default to Azure Resource Manager.
        # https://management.azure.com + /subscriptions/xxx/resourcegroups/xxx?api-version=2019-07-01
        if '://' not in url:
            url = endpoints.resource_manager.rstrip('/') + url
    
        # Replace common tokens with real values. It is for smooth experience if users copy and paste the url from
        # Azure Rest API doc
        from azure.cli.core._profile import Profile
        profile = Profile(cli_ctx=cli_ctx)
        if '{subscriptionId}' in url:
            url = url.replace('{subscriptionId}', cli_ctx.data['subscription_id'] or profile.get_subscription_id())
    
        # Prepare the Bearer token for `Authorization` header
        if not skip_authorization_header and url.lower().startswith('https://'):
            # Prepare `resource` for `get_raw_token`
            if not resource:
                # If url's origin matches the ARM endpoint, like `https://management.azure.com/`,
                # use `active_directory_resource_id` for resource, like `https://management.core.windows.net/`.
                # This follows the same behavior as `azure.cli.core.commands.client_factory._get_mgmt_service_client`
                if is_same_origin(url, endpoints.resource_manager):
                    resource = endpoints.active_directory_resource_id
                else:
                    resource = match_cloud_endpoint(url, cli_ctx)
            if resource:
                # Prepare `subscription` for `get_raw_token`
                # If this is an ARM request, try to extract subscription ID from the URL.
                # But there are APIs which don't require subscription ID, like /subscriptions, /tenants
                # TODO: In the future when multi-tenant subscription is supported, we won't be able to uniquely identify
                #   the token from subscription anymore.
                token_subscription = None
                if is_same_origin(url, endpoints.resource_manager):
                    token_subscription = _extract_subscription_id(url)
                if token_subscription:
                    logger.debug('Retrieving token for resource %s, subscription %s', resource, token_subscription)
                    token_info, _, _ = profile.get_raw_token(resource, subscription=token_subscription)
                else:
                    logger.debug('Retrieving token for resource %s', resource)
                    token_info, _, _ = profile.get_raw_token(resource)
                token_type, token, _ = token_info
                headers = headers or {}
                headers['Authorization'] = '{} {}'.format(token_type, token)
            else:
                logger.warning("Can't derive appropriate Azure AD resource from --url to acquire an access token. "
                               "If access token is required, use --resource to specify the resource")
    
        # https://requests.readthedocs.io/en/latest/user/advanced/#prepared-requests
        s = Session()
        req = Request(method=method, url=url, headers=headers, params=uri_parameters, data=body)
        prepped = s.prepare_request(req)
    
        # Merge environment settings into session
        settings = s.merge_environment_settings(prepped.url, {}, None, not should_disable_connection_verify(), None)
        _log_request(prepped)
        r = s.send(prepped, **settings)
        _log_response(r)
    
        if not r.ok:
            reason = r.reason
            if r.text:
                reason += '({})'.format(r.text)
            from .azclierror import HTTPError
>           raise HTTPError(reason, r)
E           azure.cli.core.azclierror.HTTPError: Forbidden({"error":{"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation.","innerError":{"date":"2026-06-17T06:55:51","request-id":"ca90105a-04d5-4597-8cf3-84ce0c919143","client-request-id":"ca90105a-04d5-4597-8cf3-84ce0c919143"}}})

azure-cli/src/azure-cli-core/azure/cli/core/util.py:1089: HTTPError
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 1 passed in 11.42s =========================

Posted by agent-assist live-test workflow.

@yonzhan

yonzhan commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Copilot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistencies in the way az rest parses ' and " between regular and interactive CLI

3 participants