-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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: 'charmap' codec can't encode characters in position 4790-4801: character maps to <undefined> #21409
Comments
ARM |
@shenglol Could you please help look at the issue related to |
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @armleads-azure. Issue Details
Describe the bug Recently, my script run into this problem. My az script is run on Azure Pipelines. Here is my PowerShell script on Windows Server 2019 agent: az deployment sub what-if `
--name "main$(Get-Date -Format "yyyyMMddHHmmss")" `
--location 'japaneast' `
--template-file 'main.bicep' `
--parameters `
"env=$(env.name)" `
"projectName=$(projectName)" `
"dbAdminAccount=$(sql.serveradmin.name)" `
"dbAdminPwd=$(sql.serveradmin.password)" Here is the error output: ERROR: 'charmap' codec can't encode characters in position 4790-4801: character maps to <undefined> For the following command, it works. az deployment sub validate `
--name "main$(Get-Date -Format "yyyyMMddHHmmss")" `
--location 'japaneast' `
--template-file 'main.bicep' `
--parameters `
"env=$(env.name)" `
"projectName=$(projectName)" `
"dbAdminAccount=$(sql.serveradmin.name)" `
"dbAdminPwd=$(sql.serveradmin.password)" So the error only shows when running To Reproduce Expected behavior My script is running for more than 1 month. It works before. I found it's broken today. Environment summary C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" --version"
azure-cli 2.32.0 *
WARNING: You have 2 updates available. Consider updating your CLI installation with 'az upgrade'
core 2.32.0 *
Please let us know how we are doing: https://aka.ms/azureclihats
telemetry 1.0.6
and let us know if you're interested in trying out our newest features: https://aka.ms/CLIUXstudy
Extensions:
azure-devops 0.22.0
Dependencies:
msal 1.16.0
azure-mgmt-resource 20.0.0
Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Program Files\Common Files\AzureCliExtensionDirectory'
Python (Windows) 3.8.9 (tags/v3.8.9:a743f81, Apr 6 2021, 13:22:56) [MSC v.1928 32 bit (Intel)]
Legal docs and information: aka.ms/AzureCliLegal Additional context
|
@doggy8088 Could you attach the Bicep file? |
We previously worked on a similar issue #17994 and that issue has been solved long ago. @doggy8088 could you also run the command with |
@jiasli Hi, I'm @doggy8088 's coworker, I added |
Thanks @ian90911 for the debug log which is extremely helpful. Judging by the log:
The failed code is at
Apparently Also from the log, I noticed you have a resource name with Unicode characters:
I used Python to decode it to python -c "print('\u65e5\u672c\u6771\u5340\u57df\u7684\u670d\u52d9\u5065\u5eb7\u8b66\u793a')"
日本東區域的服務健康警示 I tested without Azure CLI but only with Python on Windows agent and reproduced this issue. jobs:
- job: TestAzureCLITaskUbuntu
pool:
vmImage: 'ubuntu-latest'
steps:
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: ...
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
python3 -c "import sys; print(sys.stdout.encoding); print('汉字')"
- job: TestAzureCLITaskWindows
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: ...
scriptType: batch
scriptLocation: inlineScript
inlineScript: |
"C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -c "import sys; print(sys.stdout.encoding); print('汉字')"
The Ubuntu agent gives output
The Windows agent gives output
SolutionFor end user, the are 2 possible solutions:
For DevOps, Windows agent should use UTF-8 as |
@shenglol, I saw this line was submitted by you in #12942:
Another less optimal solution I can think of is to discard Unicode characters if except UnicodeEncodeError:
logger.warning("Unable to encode the output with %s encoding. Unsupported characters are discarded.",
out_file.encoding)
print(output.encode('ascii', 'ignore').decode('utf-8', 'ignore'),
file=out_file, end='') But this is certainly not a good solution as the resource name will be lost and the output will become useless. |
@jiasli I'm just curious why my script works for months. Only failed recently. I was running on Windows for a while. |
@jiasli I confirmed the |
I think this is because previously you don't have Chinese characters in the output of the command Anyway, please use |
Describe the bug
Recently, my script run into this problem. My az script is run on Azure Pipelines. Here is my PowerShell script on Windows Server 2019 agent:
Here is the error output:
For the following command, it works.
So the error only shows when running
az deployment sub what-if
command.To Reproduce
Expected behavior
My script is running for more than 1 month. It works before. I found it's broken today.
Environment summary
Additional context
The text was updated successfully, but these errors were encountered: