`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
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
### 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.
Contributor guide
Assessment
This issue has not been assessed yet.