Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when providing relative path to json file with --settings parameter #11600

Closed
ajklotz opened this issue Dec 17, 2019 · 20 comments
Closed
Assignees
Labels
Core CLI core infrastructure Functions az functionapp
Milestone

Comments

@ajklotz
Copy link

ajklotz commented Dec 17, 2019

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az functionapp config appsettings set

Errors:

The command failed with an unexpected error. Here is the traceback:

not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 244, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 250, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    \Stage\QueueProcessing\@queueProcessingAppSettings-CI.json
                                                             ^
SyntaxError: unexpected character after line continuation character

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.py", line 208, in update_app_settings
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 252, in shell_safe_json_parse
knack.util.CLIError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\knack\knack\cli.py", line 206, in invoke
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 603, in execute
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 661, in _run_jobs_serially
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 652, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\commands.py", line 55, in _polish_bad_errors
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 631, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 306, in __call__
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\__init__.py", line 485, in default_command_handler
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.py", line 219, in update_app_settings
ValueError: not enough values to unpack (expected 2, got 1)

To Reproduce:

Create a powershell script that executes the command below. The script and settingsFile are in different folders. So a relative path is provided to the $settingsFile.

az functionapp config appsettings set --name $functionAppName --resource-group $resourceGroupName --settings $settingsFile --slot $slot

The powershell script accepts 4 parameters

Param(
    # Name of the function app
    [Parameter(Mandatory = $true)]
    [string]$functionAppName,
    # Name of the Resource Group in Azure
    [Parameter(Mandatory = $true)]
    [string]$resourceGroupName,
    # Path of the settings file, prefix with @ symbol. Example: -settingsFile @queueProcessingAppSettings-stageSlot.json
    [Parameter(Mandatory = $true)]
    [string]$settingsFile,
    # Name of slot.
    [ValidateSet("stage", "production")]
    [Parameter(Mandatory = $true)]
    [string]$slot
)

The powershell script is executed like this:

.\functionAppSettings.ps1 -functionAppName wbqueueprocessing -resourceGroupName WB-CI -settingsFile "\Stage\QueueProcessing\@queueProcessingAppSettings-CI.json" -slot stage

Expected Behavior

Azure CLI updates application settings in Azure for the function app

Environment Summary

Windows-10-10.0.17763-SP0
Python 3.6.6
Shell: powershell.exe

azure-cli 2.0.76 *

Additional Context

Just to provide some context to the problem here...I created an Azure CLI script to deploy function apps to 5 different environments that have a production/stage slot. So my repository is structured in a way to make it easy to find these json settings files in their appropriate folder instead of having the script and 20 json files in one folder.

@mmyyrroonn mmyyrroonn added the Functions az functionapp label Dec 18, 2019
@mmyyrroonn mmyyrroonn added the Service Attention This issue is responsible by Azure service team. label Dec 18, 2019
@ghost
Copy link

ghost commented Dec 18, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ ahmedelnably, @fabiocav

@ahmedelnably
Copy link
Contributor

@ajklotz can you please try the command with the path as
-settingsFile "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json"
where the @ is at the beginning of the path?

@ahmedelnably ahmedelnably removed the Service Attention This issue is responsible by Azure service team. label Dec 19, 2019
@ajklotz
Copy link
Author

ajklotz commented Dec 19, 2019

@ajklotz can you please try the command with the path as
-settingsFile "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json"
where the @ is at the beginning of the path?

Hi, @ahmedelnably - it didn't work:

PS C:\repos\digital\CI\Scripts\AzureCLI\AzureFunctions> .\functionAppSettings.ps1 -functionAppName wbqueueprocessing -
resourceGroupName WB-CI -settingsFile "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json" -slot stage
The command failed with an unexpected error. Here is the traceback:

not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 244, in s
hell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 250, in s
hell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    @\Stage\QueueProcessing\queueProcessingAppSettings-CI.json
    ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.
py", line 208, in update_app_settings
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 252, in s
hell_safe_json_parse
knack.util.CLIError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\knack\knack\cli.py", line 206, in invoke
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", l
ine 603, in execute
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", l
ine 661, in _run_jobs_serially
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", l
ine 652, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\command
s.py", line 55, in _polish_bad_errors
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", l
ine 631, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", l
ine 306, in __call__
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\__init__.py", line 485,
in default_command_handler
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.
py", line 219, in update_app_settings
ValueError: not enough values to unpack (expected 2, got 1)

@ahmedelnably
Copy link
Contributor

@ajklotz That is weird, I tried it and it did work.
Can you please try the command without your script?

az functionapp config appsettings set -n wbqueueprocessing -g WB-CI --settings "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json" --slot stage

@ajklotz
Copy link
Author

ajklotz commented Dec 19, 2019

Still didn't work. Do we have different versions of Azure CLI or something?

PS C:\repos\digital\CI\Scripts\AzureCLI\AzureFunctions> az functionapp config appsettings set -n wbqueueprocessing -g WB-CI --settings "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json" --slot stage
The command failed with an unexpected error. Here is the traceback:

not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 244, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 250, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    @\Stage\QueueProcessing\queueProcessingAppSettings-CI.json
    ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.py", line 208, in update_app_settings
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\util.py", line 252, in shell_safe_json_parse
knack.util.CLIError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\knack\knack\cli.py", line 206, in invoke
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 603, in execute
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 661, in _run_jobs_serially
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 652, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\commands.py", line 55, in _polish_bad_errors
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 631, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\commands\__init__.py", line 306, in __call__
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli-core\azure\cli\core\__init__.py", line 485, in default_command_handler
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-umfcm_n2\azure-cli\azure\cli\command_modules\appservice\custom.py", line 219, in update_app_settings
ValueError: not enough values to unpack (expected 2, got 1)
PS C:\WBSRC\wbdigital\CI\Scripts\AzureCLI\AzureFunctions> az --version
azure-cli                         2.0.76 *

command-modules-nspkg              2.0.3
core                              2.0.76 *
nspkg                              3.0.4
telemetry                          1.0.4

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

Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal


You have 2 updates available. Consider updating your CLI installation.

@ajklotz
Copy link
Author

ajklotz commented Dec 19, 2019

I went ahead and updated to azure-cli v2.0.78 and still had the same problem.

@ahmedelnably
Copy link
Contributor

Can you please double check that your json file is correctly formatted?
Also does the command succeed if you have the json file in the same directory?

@ajklotz
Copy link
Author

ajklotz commented Dec 19, 2019

Can you please double check that your json file is correctly formatted?
Also does the command succeed if you have the json file in the same directory?

Yes, the command succeeds if the json file is in the same directory. Because it succeeds in the same directory, I know that the json file is correctly formatted.

@ahmedelnably
Copy link
Contributor

cc/ @ankitkumarr and @panchagnula for guidance as I ran out of ideas 😑

@ajklotz
Copy link
Author

ajklotz commented Dec 19, 2019

I believe that there is a fundamental problem with the Azure CLI because even if I try to do a similar scenario using ARM templates with az group deployment create with a json file in another folder, I get an error. It seems that the error exceptions are caught, and a more generic error is returned, however.

@yonzhan yonzhan added the Service Attention This issue is responsible by Azure service team. label Dec 21, 2019
@ghost
Copy link

ghost commented Dec 21, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ ahmedelnably, @fabiocav

@ahmedelnably
Copy link
Contributor

@yonzhan, who from the core cli team help with this?

@ahmedelnably ahmedelnably removed the Service Attention This issue is responsible by Azure service team. label Dec 21, 2019
@yonzhan
Copy link
Collaborator

yonzhan commented Dec 22, 2019

@ahmedelnably If the CLI commands are contributed by service team and CLI team currently does not take over, we will mark the Service Attention label. Do you think it is not the case?

@ajklotz
Copy link
Author

ajklotz commented Dec 26, 2019

I wish I knew why it worked for ahmedelnably. Any update on this?

@ajklotz
Copy link
Author

ajklotz commented Dec 30, 2019

@ahmedelnably You mentioned that this worked for you. Did you try this in PowerShell or in Bash? If you tried in Bash, can you try in PowerShell?

@ahmedelnably
Copy link
Contributor

@ajklotz, I did try in PowerShell.
@yonzhan we believe this issue is not a module issue, that's why we want assistance from the core team

@jiasli jiasli self-assigned this Dec 31, 2019
@jiasli jiasli added the Core CLI core infrastructure label Dec 31, 2019
@jiasli
Copy link
Member

jiasli commented Dec 31, 2019

On Windows, relative path shouldn't start with \. So "@\Stage\QueueProcessing\queueProcessingAppSettings-CI.json" should be "@Stage\QueueProcessing\queueProcessingAppSettings-CI.json" instead.

This can be verified with:

>python

>>> import codecs

>>> codecs.open("\\temp\\foo.json")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\{}\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: '\\temp\\foo.json'

>>> codecs.open("temp\\foo.json")
<_io.TextIOWrapper name='temp\\foo.json' mode='r' encoding='cp65001'>

@ajklotz
Copy link
Author

ajklotz commented Dec 31, 2019

@jiasli That was it, you solved my problem. Thank you so much.

@asishr14
Copy link

asishr14 commented May 5, 2020

@ajklotz I still have this issue only when I use the Azure CLI task from Azure devOps pipeline on its windows agent (azure-cli 2.5.0 *), though I can run this same on my local, mysettings.json in the source dir only. Have same error even after explicitly specifying the path "@$(Build.SourcesDirectory)\mysettings.json"

The command failed with an unexpected error. Here is the traceback:

not enough values to unpack (expected 2, got 1)
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-d4ph977u\azure-cli-core\azure\cli\core\util.py", line 288, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-d4ph977u\azure-cli-core\azure\cli\core\util.py", line 294, in shell_safe_json_parse
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    @mysettings.json

@vsha041
Copy link

vsha041 commented Nov 16, 2021

@asishr14 - Hopefully you have already solved it but I was in similar situation. In YAML pipelines, you can specify the working directory and so the path is not required at all. In the below example the JSON file XYZ.json exists in this location in the GIT repository - $(System.DefaultWorkingDirectory)/A/B/C

- task: AzureCLI@2
  displayName: 'Deploy API'
  inputs:
    azureSubscription: 'XYZ'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    workingDirectory: $(System.DefaultWorkingDirectory)/A/B/C
    inlineScript: |
      az webapp deploy --name XYZ --resource-group XYZ --slot XYZ --src-path "$(Pipeline.Workspace)/XYZ.zip" --type zip;
      az webapp config appsettings set --name XYZ  --resource-group XYZ  --slot XYZ --settings "@XYZ.json"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core CLI core infrastructure Functions az functionapp
Projects
None yet
Development

No branches or pull requests

7 participants