azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az rest command working on v2.0.76 but not v2.1.0

Open JeffinBao opened this issue 6 years ago • 8 comments

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug I used the az rest --method put --uri https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/sites/{app_name}/config/web?api-version=2019-08-01 --body '{\"properties\":{\"healthCheckPath\":\"/version\"}}' with v2.0.76, it worked fine. But when I tried the same command with v2.1.0, it gave this error: ERROR: Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})

Then, I changed the command to az rest --method put --uri https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Web/sites/$APP_NAME/config/web?api-version=2019-08-01 --body '{\"properties\":{\"healthCheckPath\":\"/actuator/health\"}}' --headers '{\"Content-Type\":\"application/json\"}', The difference is to add application/json content type header. But I got another error: ERROR: not enough values to unpack (expected 2, got 1).

I also changed the format of header to --headers "Content-Type=application/json" as per documentation(https://docs.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az-rest). But I got another error: ERROR: Bad Request({"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Invalid property identifier character: \\. Path '', line 1, position 1.'."}}). I verified this --headers "Content-Type=application/json" with v2.2.0, it works. Not sure what happens to v2.1.0.

I didn't know why the same command working for v2.0.76, but not working for v2.1.0. Can someone figure it out? Many thanks in advance.

To Reproduce Please see above

Expected behavior The same command should work for both versions.

Environment summary

Additional context

JeffinBao avatar Apr 16 '20 18:04 JeffinBao

add to S169

yonzhan avatar Apr 16 '20 23:04 yonzhan

add to S171

yonzhan avatar May 03 '20 01:05 yonzhan

@JeffinBao Sorry, I can't reproduce this problem in version 2.1.0 of CLI. Can you reproduce this problem now? If you can, please add --debug to the original command and email the printed information to me~ My email address is [email protected], thanks~

zhoxing-ms avatar Jun 02 '20 05:06 zhoxing-ms

I figured it out, I think it was some environment issue. Thank you!

JeffinBao avatar Jun 11 '20 13:06 JeffinBao

For anyone find this when searching for:

Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})

It is most likely that you have 2 issues: Your json needs to be a single line json string, escaped. I had a multi line json in a variable in PowerShell, and when converting it to a single line and escaping the " (double qoute) to \" (slash double quote) the error went away.

Splaxi avatar Nov 28 '20 14:11 Splaxi

For anyone find this when searching for:

Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})

It is most likely that you have 2 issues: Your json needs to be a single line json string, escaped. I had a multi line json in a variable in PowerShell, and when converting it to a single line and escaping the " (double qoute) to " (slash double quote) the error went away.

And I just hit the same error again, only to search for the error, to end up here - getting my own suggestion and to learn that the issue is still the same. Single line json, escaped double quotes...

Splaxi avatar Apr 01 '22 06:04 Splaxi

For anyone find this when searching for:

Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})

It is most likely that you have 2 issues: Your json needs to be a single line json string, escaped. I had a multi line json in a variable in PowerShell, and when converting it to a single line and escaping the " (double qoute) to " (slash double quote) the error went away.

And I just hit the same error again, only to search for the error, to end up here - getting my own suggestion and to learn that the issue is still the same. Single line json, escaped double quotes...

how do you escape them in Powershell? Backslash and the following does not work:

az rest --method patch --uri "${BastionId}?api-version=2021-05-01" --body "{`"properties`":{`"enableTunneling`":`"false`"}}" -o none  --only-show-errors
Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '<null>' is not supported. Only 'application/json' is supported."}})

jetnet avatar May 07 '22 19:05 jetnet

For PowerShell quoting issue, please see https://github.com/Azure/azure-cli/issues/15529.

jiasli avatar May 09 '22 03:05 jiasli