Azure / Azure/azure-cli-extensions
[functionapp] `az functionapp deploy` crashes (JSONDecodeError) because OneDeploy responses contain JSON + appended HTML (Flex Consumption). Also blocks with RunFromExternalUrlException when WEBSITE_RUN_FROM_PACKAGE is set.
- Dominant language
- Python
- Stars
- 454
- Forks
- 1.7k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 64
Description
Source: https://github.com/Azure/azure-cli/issues/32655 (by @JKamsker)
Affected extension: `functionapp` (`src/functionapp/`)
---
<<>>
# Issue #32655 (by @JKamsker)
## Title
`az functionapp deploy` crashes (JSONDecodeError) because OneDeploy responses contain JSON + appended HTML (Flex Consumption). Also blocks with RunFromExternalUrlException when WEBSITE_RUN_FROM_PACKAGE is set.
## Body
### Describe the bug
`az functionapp deploy` (preview) crashes with an unhandled JSON parsing exception when deploying a zip package to a **Linux Azure Function App on Flex Consumption**.
The underlying deploy request is accepted (202) and returns JSON that includes a deployment id, but the response body appears to contain **valid JSON followed by an appended HTML “Server Error in '/' Application” page**. This causes Azure CLI to throw `JSONDecodeError: Extra data` and exit unexpectedly.
In the same scenario, querying the deployment record shows the deployment fails with:
`RunFromExternalUrlException: The app setting WEBSITE_RUN_FROM_PACKAGE is set to a remote URL. Therefore, Deployment is not needed... set WEBSITE_RUN_FROM_PACKAGE ... and manually call synctriggers.`
Even if this configuration is expected to block zip deployment, the CLI should **not crash** because the response contains mixed content (JSON + HTML). Instead it should surface the service error cleanly.
This looks related to existing reports about JSON responses having HTML appended (for Flex Consumption deployments), e.g. azure-cli #32443 and #30960.
### Related command
PowerShell:
'''
az functionapp deploy -g -n `
--type zip `
--src-url "" `
--verbose
'''
Deployment status query that also returns JSON + appended HTML:
'''
$sub=""
$rg=""
$app=""
$dep=""
az rest --method get `
--url "https://management.azure.com/subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.Web/sites/$app/deployments/$dep" `
--url-parameters api-version=2018-02-01 `
-o jsonc
'''
---
### Errors
From `az functionapp deploy ... --verbose` (truncated + redacted):
'''
Response content:
{"id":"...","properties":{"deployment":{"id":"", ...}}}
Runtime Error
Server Error in '/' Application.
Runtime Error
... suggests adding to web.config ...
'''
Then Azure CLI throws:
'''
The command failed with an unexpected error. Here is the traceback:
Extra data: line 1 column (char )
...
json.decoder.JSONDecodeError: Extra data: line 1 column (char )
...
requests.exceptions.JSONDecodeError: Extra data: line 1 column (char )
'''
Deployment status call returns `status=3` and the service error (and again has HTML appended after JSON):
'''
"status": 3,
"status_text": "RunFromExternalUrlException: The app setting WEBSITE_RUN_FROM_PACKAGE is set to a remote URL. Therefore, Deployment is not needed in this case. For new deployment, just set the WEBSITE_RUN_FROM_PACKAGE to the remote URL of the latest zip package and manually call synctriggers."
'''
### Issue script & Debug output
Repro script (PowerShell). Please run with `--debug` and paste full output below (redact secrets):
'''
$sub=""
$rg=""
$app=""
$pkg=""
# 1) Deploy
az functionapp deploy -g $rg -n $app --type zip --src-url $pkg --verbose --debug
# 2) Extract the deployment GUID from the deploy output (deployment id)
$dep=""
# 3) Query deployment record (this also shows JSON + appended HTML in the response)
az rest --method get --debug `
--url "https://management.azure.com/subscriptions/$sub/resourceGroups/$rg/providers/Microsoft.Web/sites/$app/deployments/$dep" `
--url-parameters api-version=2018-02-01 `
-o jsonc
'''
In the debug output, the key symptom is that the response body contains JSON followed by `` and an ASP.NET-style runtime error page.
### Expected behavior
* CLI should **not crash** with an unhandled `JSONDecodeError`.
* If the service returns non-JSON or mixed content, CLI should:
* fall back to raw-text handling (or parse the first JSON object only),
* and return a clear, actionable error message.
* If `WEBSITE_RUN_FROM_PACKAGE` blocks deployment, CLI should surface that message cleanly (and ideally provide guidance: update `WEBSITE_RUN_FROM_PACKAGE` + call `syncfunctiontriggers`).
### Environment Summary
azure-cli 2.77.0
core 2.77.0
telemetry 1.1.0
Extensions:
application-insights 1.2.3
log-analytics 1.0.0b1
resource-graph 2.1.1
Dependencies:
msal 1.34.0b1
azure-mgmt-resource 23.3.0
Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\Jonas\.azure'
Extensions directory 'C:\Users\Jonas\.azure\cliextensions'
Python (Windows) 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)]
Legal docs and information: aka.ms/AzureCliLegal
### Additional context
* The Function App has `WEBSITE_RUN_FROM_PACKAGE` set to a remote URL (external package).
* The deployment record reports `RunFromExternalUrlException` suggesting “deployment not needed” and to “set WEBSITE_RUN_FROM_PACKAGE to latest zip and manually call synctriggers”.
* Regardless of the correct deployment approach, the CLI bug is that **JSON responses appear to have HTML appended**, causing JSON parsing to fail (observed both during `az functionapp deploy` and when querying deployment status).
* Related issues: #32443 and #30960.
## Comments
### Comment by @azure-client-tools-bot-prd[bot]
Hi @JKamsker,
2.77.0 is not the latest Azure CLI(2.82.0).
If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.
### Comment by @yonzhan
Thank you for opening this issue, we will look into it.
### Comment by @microsoft-github-policy-service[bot]
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kamperiadis, @amamounelsayed, @khkh-ms.
### Comment by @github-actions[bot]
Here are some similar issues that might help you. Please check if they can solve your problem.
- #32443
- #30960
- #9369
------------
**Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)**
### Solution 1:
This issue might be caused by extra HTML being delivered along with the JSON payload from the deploy REST endpoint. I suspect that is the bug that is triggering this CLI error. The CLI tool should handle such cases gracefully by either parsing only the JSON part or providing a clear error message.
**Reference**:
- https://github.com/azure/azure-cli/issues/32443#issuecomment-3561528060
- https://github.com/azure/azure-cli/issues/30960#issuecomment-3561454559
### Solution 2:
Another issue which causes this is when Firewall/Access Restriction rules are enabled for the scm site and the machine deploying does not have IP allowed. Ensure that the machine deploying has the correct IP allowed in the Access Restriction rules.
**Reference**:
- https://github.com/azure/azure-cli/issues/9369#issuecomment-503776318
_Powered by [issue-sentinel](https://github.com/Azure/issue-Sentinel)_
### Comment by @microsoft-github-policy-service[bot]
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kamperiadis, @amamounelsayed, @khkh-ms.
### Comment by @tibbing
This breaks usage [from the Terraform provider](https://learn.microsoft.com/en-us/azure/templates/microsoft.web/2022-09-01/sites/extensions-onedeploy?pivots=deployment-language-terraform) as well, i.e.
''' hcl
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Web/sites/extensions@2022-09-01"
name = "onedeploy"
parent_id = "string"
}
'''
> Error: Failed to create/update resource
> │
> │ with azapi_resource.function_package_deploy,
> │ on deployment.tf line 86, in resource "azapi_resource" "function_package_deploy":
> │ 86: resource "azapi_resource" "function_package_deploy" {
> │
> │ creating/updating Resource: (ResourceId
> │ "/subscriptions//resourceGroups//providers/Microsoft.Web/sites/<[~]function>/extensions/OneDeploy" / Api
> │ Version "2022-09-01"): invalid character '<' after top-level value
<<>>
Contributor guide
Assessment
This issue has not been assessed yet.