ERROR: 'charmap' codec can't encode characters in position 4790-4801: character maps to <undefined>
See original GitHub issue
az feedback
auto-generates most of the information requested below, as of CLI version 2.0.62
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 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
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
python - UnicodeEncodeError: 'charmap' codec can't encode
The code is ugly with all that decoding, encoding, and decoding. It solves the problem for just this case. If I port the...
Read more >'charmap' codec can't encode characters in position | bobbyhadz
The Python "UnicodeEncodeError: 'charmap' codec can't encode characters in position" occurs when we use an incorrect codec to encode a string to ...
Read more >'charmap' codec can't encode characters in position 0-14 ...
Hi! How to solve "UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-14: character maps to " for this code: stockList ...
Read more >UnicodeEncodeError: 'charmap' codec can't encode character
Question: I've discovered an error on your example ( https://www.example-code.com/chilkat2-python/xml_i.asp ) ...
Read more >'charmap' codec can't encode characters in position 529-531 ...
i got the below error when i tried Pabot with browser library Calling method 'end_keyword' of listener 'RobotStackTracer' failed: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jiasli I confirmed the
ubuntu-latest
agent works. Thanks.Thanks @ian90911 for the debug log which is extremely helpful.
Judging by the log:
The failed code is at
https://github.com/Azure/azure-cli/blob/67568014e3df1f183b92ee1ad7699b3b86f35dc0/src/azure-cli/azure/cli/command_modules/resource/custom.py#L930
Apparently
print
throws this error.Also from the log, I noticed you have a resource name with Unicode characters:
I used Python to decode it to
I tested without Azure CLI but only with Python on Windows agent and reproduced this issue.
The Ubuntu agent gives output
The Windows agent gives output
Solution
For end user, the are 2 possible solutions:
stdout
is UTF-8.stdout
’s encoding is cp1252 which is not able to handle Unicode. For example, you may rename it tojapan-north-service-health-alert
.For DevOps, Windows agent should use UTF-8 as
stdout
’s encoding. We will internally work with Azure DevOps team on this topic.