You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-ref-conceptual/Latest-version/use-azure-cli-successfully-quoting.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -309,7 +309,7 @@ flag reveals the actual arguments received by the Azure CLI in [Python's syntax]
309
309
310
310
311
311
312
-
For more information on troubleshooting Azure CLI commands with `--debug`, see [Troubleshooting Azure CLI](./use-azure-cli-successfully-troubleshooting.md#the---debug-parameter).
312
+
For more information on troubleshooting Azure CLI commands with `--debug`, see [Troubleshooting Azure CLI](./use-azure-cli-successfully-troubleshooting.md#the-debug-parameter).
description: Learn to use the Azure CLI successfully by understanding common Azure CLI errors and how to fix them.
4
-
ms.date: 12/10/2024
5
4
ms.custom: devx-track-azurecli
6
5
#customer intent: As an Azure CLI customer, I want to be able to search for Azure CLI errors and receive more explanation than what is available from the in-line error message. Just don't tell me what an error is, also tell me how to fix it.
7
6
---
@@ -15,16 +14,17 @@ Most errors returned by the Azure CLI fall into one of these categories:
15
14
|Error category | General error cause |
16
15
|-|-|
17
16
|Unrecognized argument | A parameter is misspelled or doesn't exist.
18
-
|[Required argument missing](#error-arguments-are-expected-or-required) | A required parameter isn't specified or only one of two "parameter pairs" is specified. A parameter might also be misspelled.
17
+
|[Required argument missing][13] | A required parameter isn't specified or only one of two "parameter pairs" is specified. A parameter might also be misspelled.
19
18
|Mutually exclusive argument | Two or more parameters can't be specified together.
20
-
|[Invalid argument value](#error-invalid-value-or-doesnt-exist) | Parameter _value_ isn't valid. This error is often due to quoting, an escape character or spacing.
19
+
|[Invalid argument value][14] | Parameter _value_ isn't valid. This error is often due to quoting, an escape character or spacing.
21
20
|Bad request | An HTTP status code of 400 returns this error. Check for a missing space, missing parameter dash, or an extra or missing single or double quotation mark. This error also happens when a parameter value doesn't contain an allowed value.
22
-
|[Resource not found](#error-resource-not-found) | An Azure resource referenced in a parameter value can't be found.
21
+
|[Resource not found][15] | An Azure resource referenced in a parameter value can't be found.
23
22
|Authentication | Microsoft Entra authentication failed.
24
23
25
-
## The `--debug` parameter
24
+
## The debug parameter
26
25
27
-
One of the best ways to see what the Azure CLI is executing for each Azure CLI reference command is to use the `--debug` parameter. Here's examples of `--debug` for both a failed and successful command:
26
+
One of the best ways to see what the Azure CLI is executing for each reference command is to use the
27
+
`--debug` parameter. Here are examples of `--debug` for both a failed and successful command:
28
28
29
29
```azurecli
30
30
# Error example: Create a resource group, but omit the quotes around the resource group name.
cli.__main__: Command ran in 1.829 seconds (init: 0.111, invoke: 1.718)
81
81
```
82
82
83
-
For examples of `--debug` for JSON formatting, see [Quoting differences between scripting languages - JSON strings](./use-azure-cli-successfully-quoting.md#json-strings).
83
+
For examples of `--debug` for JSON formatting, see
84
+
[Quoting differences between scripting languages - JSON strings][08].
84
85
85
86
## Common syntax errors
86
87
87
-
Although the Azure CLI can run in both Bash, PowerShell and Windows Cmd, there are syntax differences between scripting languages. Azure CLI scripts containing single quotes, double quotes, and escape characters usually must be modified when copied between languages. This challenge reveals itself most often in parameter values, especially in values assigned to the `--query` parameter. Here are some common error messages:
88
+
Although the Azure CLI can run in Bash, PowerShell, and the Windows Command Prompt (`cmd.exe`),
89
+
there are syntax differences between scripting languages. Azure CLI scripts containing single
90
+
quotes, double quotes, and escape characters often require modification when copied between
91
+
languages. This challenge is most often revealed in parameter values, particularly in those assigned
92
+
to the `--query` parameter. Here are some common error messages:
88
93
89
-
* "**Bad request ...{something} is invalid**" might be caused by a space, single or double quotation mark, or lack of a quote.
94
+
-**Bad request ...{something} is invalid**: This error might be caused by a space, single or double
95
+
quotation mark, or lack of a quote.
90
96
91
-
* "**Unexpected token...**" is seen when there's an extra space or quote.
97
+
-**Unexpected token...**: This error is seen when there's an extra space or quote.
92
98
93
-
* "**Invalid jmespath_type value**" error often comes from incorrect quoting in the `--query` parameter.
99
+
-**Invalid jmespath_type value**: This error often comes from incorrect quoting in the `--query`
100
+
parameter.
94
101
95
-
* "**Variable reference is not valid**" is received when a string isn't formatted properly often due to concatenation or a missing escape character.
102
+
-**Variable reference is not valid**: This error is received when a string isn't formatted
103
+
properly, often due to concatenation or a missing escape character.
96
104
97
-
* "**Unrecognized arguments**" is often caused by an incorrect line continuation character or misspelled parameter name.
105
+
-**Unrecognized arguments**: This error is often caused by an incorrect line continuation character
106
+
or misspelled parameter name.
98
107
99
-
* "**Missing expression after unary operator**" is seen when a line continuation character is missing.
108
+
-**Missing expression after unary operator**: This error is seen when a line continuation character
109
+
is missing.
100
110
101
-
There are several Azure CLI articles dedicated to explaining syntax errors and providing working examples:
111
+
There are several Azure CLI articles dedicated to explaining syntax errors and providing working
112
+
examples:
102
113
103
-
*[Quoting differences between scripting languages](./use-azure-cli-successfully-quoting.md)
104
-
*[Syntax differences in Bash, PowerShell, and Cmd](./get-started-tutorial-2-environment-syntax.md) tutorial
105
-
* Find many `--query` parameter examples in [How-to query Azure CLI command output using a JMESPath query](./use-azure-cli-successfully-query.md)
106
-
*[How-to use the Azure CLI in a Bash scripting language](./use-azure-cli-successfully-bash.md)
107
-
*[Considerations for running the Azure CLI in a PowerShell scripting language](./use-azure-cli-successfully-powershell.md)
114
+
-[Quoting differences between scripting languages][07]
115
+
-[Syntax differences in Bash, PowerShell, and Cmd][03] tutorial
116
+
- Find many `--query` parameter examples in
117
+
[How-to query Azure CLI command output using a JMESPath query][06]
118
+
-[How-to use the Azure CLI in a Bash scripting language][04]
119
+
-[Considerations for running the Azure CLI in a PowerShell scripting language][05]
108
120
109
121
> [!TIP]
110
-
> If you can't resolve a command error, try using a different scripting language. **Most Azure CLI documentation is written and tested in Azure Cloud Shell (ACS) with a Bash scripting language.** If you can get an article example to execute in ACS Bash, but it won't execute in Windows PowerShell, review your use of single and double quotes, and escape characters.
122
+
> If you can't resolve a command error, try using a different scripting language. Most Azure CLI
123
+
> documentation is written and tested in Azure Cloud Shell, which uses the Bash scripting language.
124
+
> If you can get an article example to execute in Bash, but it doesn't execute in PowerShell, review
125
+
> your use of single and double quotes, and escape characters.
111
126
112
127
## Error: Invalid value or doesn't exist
113
128
114
-
These errors often occur when trying to use a variable value that contains an incorrect format. The default output for Azure CLI is JSON, so if you're trying to store an ID for an Azure resource in a variable, you must specify `--output tsv`. Here's an example:
129
+
These errors often occur when trying to use variable values that contain an incorrect format. The
130
+
default output for Azure CLI is JSON. If you're trying to store an ID for an Azure resource in a
131
+
variable, you must specify `--output tsv`. Here's an example:
115
132
116
133
```azurecli
117
134
# Get a subscription that contains a name or phrase
@@ -144,32 +161,43 @@ az account set --subscription $subscriptionID
144
161
145
162
## Error: Arguments are expected or required
146
163
147
-
You receive this error when an Azure CLI command is missing a required parameter, or _there's a typographical error that causes the Azure CLI to incorrectly parse the reference command_. When working with a script, you also receive this error when one or more conditions are true:
164
+
You receive this error when an Azure CLI command is missing a required parameter, or there's a
165
+
typographical error that causes the Azure CLI to incorrectly parse the reference command. When
166
+
working with a script, you also receive this error when one or more conditions are true:
148
167
149
-
* A line continuation character is missing or incorrect.
150
-
* A trailing space exists on the right side of a line continuation character when working in the PowerShell scripting language. At this time, [splatting](/powershell/module/microsoft.powershell.core/about/about_splatting) isn't supported with Azure CLI commands.
151
-
* A variable name contains a special character, such as a dash (-).
168
+
- A line continuation character is missing or incorrect.
169
+
- A trailing space exists on the right side of a line continuation character when working in the
170
+
PowerShell scripting language. PowerShell [splatting][12] is only supported with arrays and not
171
+
hash tables with Azure CLI commands.
172
+
- A variable name contains a special character, such as a dash (-).
152
173
153
174
## Error: Resource not found
154
175
155
-
When the Azure CLI can't find the resource name or ID passed in a parameter value, it's usually because of one of these reasons:
176
+
When the Azure CLI can't find the resource name or ID passed in a parameter value, it's usually
177
+
because of one of these reasons:
156
178
157
-
* The resource name or ID is spelled incorrectly.
158
-
* The resource name contains special characters and isn't surrounded by single or double quotes.
159
-
* The value being passed to a variable has unseen leading or trailing spaces.
160
-
* The resource exists, but is in a different subscription.
179
+
- The resource name or ID is spelled incorrectly.
180
+
- The resource name contains special characters and isn't surrounded by single or double quotes.
181
+
- The value being passed to a variable has unseen leading or trailing spaces.
182
+
- The resource exists, but is in a different subscription.
161
183
162
184
## Error: Failed to parse string as JSON
163
185
164
-
There are quoting differences between Bash, PowerShell in Linux, and PowerShell in Windows. Furthermore, different versions of PowerShell can produce different results. For complex parameters, like a JSON string, the best practice is to use Azure CLI's `@<file>` convention to bypass a shell's interpretation. For more information, see one of these articles:
186
+
There are quoting differences between Bash, PowerShell in Linux, and PowerShell in Windows.
187
+
Furthermore, different versions of PowerShell can produce different results. For complex parameters,
188
+
such as a JSON string, the best practice is to use Azure CLI's `@<file>` convention to bypass the
189
+
shell's interpretation. For more information, see one of these articles:
165
190
166
-
For JSON syntax examples for Bash, PowerShell and Cmd.exe, see [Quoting differences between scripting languages - JSON strings](./use-azure-cli-successfully-quoting.md#json-strings) tutorial.
191
+
For JSON syntax examples for Bash, PowerShell, and `cmd.exe`, see
192
+
[Quoting differences between scripting languages - JSON strings][08] tutorial.
167
193
168
194
## Error: InvalidTemplateDeployment
169
195
170
-
When you try to create an Azure resource in a location that doesn't offer that resource, you receive an error similar to this message: "Following SKUs have failed for Capacity Restrictions: myDesiredSkuName' is currently not available in location 'mySpecifiedLocation'."
196
+
When you try to create an Azure resource in a location that doesn't offer that resource, you receive
197
+
an error similar to this message: "Following SKUs have failed for Capacity Restrictions:
198
+
myDesiredSkuName' is currently not available in location 'mySpecifiedLocation'".
171
199
172
-
Here's a full error example for a VM that can't be created in the `westus` location:
200
+
Here's a complete error example for a VM that can't be created in the `westus` location:
173
201
174
202
```azurecli
175
203
{"error":{"code":"InvalidTemplateDeployment","message":"The template deployment 'vm_deploy_<32 character ID>'
@@ -184,15 +212,22 @@ The solution is to change a property of your requested Azure resource, or try a
184
212
185
213
## Error: Subscription not found
186
214
187
-
Assuming that you have not incorrectly typed a subscription name or ID, this error occurs when a resource provider is not registered in the active subscription. For example, if you want to execute `az storage account create`, the `Microsoft.Storage` provider must be registered. To register a resource provider, see [Azure resource providers and types](/azure/azure-resource-manager/management/resource-providers-and-types).
215
+
Assuming that you didn't type in the subscription name or ID incorrectly, this error occurs when a
216
+
resource provider isn't registered in the active subscription. For example, if you want to execute
217
+
`az storage account create`, the `Microsoft.Storage` provider must be registered. To register a
218
+
resource provider, see [Azure resource providers and types][10].
188
219
189
-
## Error: Bad handshake...certificate verify failed
220
+
## Error: Bad handshakecertificate verify failed
190
221
191
-
See [Work behind a proxy](#work-behind-a-proxy) for information on how to resolve this error.
222
+
See [Work behind a proxy][16] for information on how to resolve this error.
192
223
193
224
## Work behind a proxy
194
225
195
-
If you're using Azure CLI over a proxy server that uses self-signed certificates, the Python [requests library](https://github.com/kennethreitz/requests) used by the Azure CLI might cause the following error: `SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)`. To address this error, set the environment variable `REQUESTS_CA_BUNDLE` to the path of CA bundle certificate file in PEM format.
226
+
If you're using Azure CLI over a proxy server that uses self-signed certificates, the Python
227
+
[requests library][18] used by the Azure CLI might cause the following error:
Append the proxy server's certificate to the CA bundle certificate file, or copy the contents to another certificate file. Then set `REQUESTS_CA_BUNDLE` to the new file location. Here's an example:
240
+
Append the proxy server's certificate to the CA bundle certificate file, or copy the contents to
241
+
another certificate file. Then set `REQUESTS_CA_BUNDLE` to the new file location. Here's an example:
206
242
207
243
```console
208
244
<Original cacert.pem>
@@ -212,16 +248,42 @@ Append the proxy server's certificate to the CA bundle certificate file, or copy
212
248
-----END CERTIFICATE-----
213
249
```
214
250
215
-
Some proxies require authentication. The format of the `HTTP_PROXY` or `HTTPS_PROXY` environment variables should include the authentication, such as `HTTPS_PROXY="https://username:password@proxy-server:port"`. For details, see [How to configure proxies for the Azure SDK for Python](/azure/developer/python/sdk/azure-sdk-configure-proxy?tabs=bash).
251
+
Some proxies require authentication. The format of the `HTTP_PROXY` or `HTTPS_PROXY` environment
252
+
variables should include the authentication, such as
253
+
`HTTPS_PROXY="https://username:password@proxy-server:port"`. For details, see
254
+
[How to configure proxies for the Azure SDK for Python][11].
216
255
217
256
## Service principals
218
257
219
-
For information on troubleshooting service principals, see [Cleanup and Troubleshooting](./azure-cli-sp-tutorial-8.md#troubleshoot-service-principals) in the [Work with service principals](./azure-cli-sp-tutorial-1.md) tutorial.
258
+
For information on troubleshooting service principals, see [Cleanup and Troubleshooting][02] in the
259
+
[Work with service principals][01] tutorial.
220
260
221
261
## Other issues
222
262
223
-
If you experience a product issue with Azure CLI not listed in this article, [file an issue on GitHub](https://github.com/Azure/azure-cli/issues/new/choose).
263
+
If you experience a product issue with Azure CLI not listed in this article,
264
+
[file an issue on GitHub][17].
224
265
225
266
## See also
226
267
227
-
*[Tips for using the Azure CLI successfully](./use-azure-cli-successfully-tips.md)
0 commit comments