question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

az acr build : UnicodeEncodeError: 'charmap' codec can't encode characters in position 57-96

See original GitHub issue

Describe the bug

When an az acr build is run on Windows 10 using Git Bash and pip, it appears that the pip package install progress characters crash the log from the build. The build succeeds and the image is created in the container registry, even though the build is reported to have failed. The failure appears to be only associated with the log stream.

If the same command is run using a command prompt and az acr build it succeeds. If the command is used with Git Bash and Docker desktop, it also succeeds.

Command Name az acr build

Errors:

The command failed with an unexpected error. Here is the traceback:
'charmap' codec can't encode characters in position 57-96: character maps to <undefined>
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 658, in execute
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 721, in _run_jobs_serially
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 692, in _run_job
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 328, in __call__
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/build.py", line 143, in acr_build
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_stream_utils.py", line 58, in stream_logs
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/acr/_stream_utils.py", line 143, in _stream_logs
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 41, in write
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 162, in write
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 187, in write_and_convert
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\colorama/ansitowin32.py", line 195, in write_plain_text
  File "encodings\cp1252.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode characters in position 57-96: character maps to <undefined>

To Reproduce:

Steps to reproduce the behaviour. Note that argument values have been redacted, as they may contain sensitive information.

The present working directory should contain Dockerfile, app.py, requirements.txt.

app.py

from flask import Flask
from flask import request

app = Flask(__name__)


@app.route("/")
def hello_server():
    host_and_port = request.headers.get('Host')
    fragments = host_and_port.split(":")
    hostname = fragments[0]
    port = "80"
    if len(fragments) > 1:
        port = fragments[1]
    return f"<p>Hello from {hostname}, listening on port {port}.</p>"


if __name__ == '__main__':
    app.run(debug=True)

requirements.txt

Flask>=2.0
gunicorn>20.0
  • az acr build --resource-group {} --registry {} --image {} {}

The az acr build from Git Bash with and the Dockerfile:

# syntax=docker/dockerfile:1
FROM python:slim-bullseye
WORKDIR /app
COPY . .
RUN pip3 install --upgrade pip && pip3 install -r requirements.txt
ENV PORT=5000
CMD ["sh", "-c", "gunicorn --bind 0.0.0.0:$PORT app:app"]

crashes.

However, the az acr build from Git Bash and the Dockerfile:

# syntax=docker/dockerfile:1
FROM python:slim-bullseye
WORKDIR /app
COPY . .
RUN pip3 install --upgrade --progress-bar off pip && pip3 install --progress-bar off -r requirements.txt
ENV PORT=5000
CMD ["sh", "-c", "gunicorn --bind 0.0.0.0:$PORT app:app"]

succeeds.

Expected Behaviour

I expect that the build log should not crash when the build is run from Git Bash.

Environment Summary

Windows-10-10.0.19042-SP0
Python 3.10.4
Installer: MSI

azure-cli 2.36.0

Extensions:
account 0.2.2
azure-devops 0.23.0
db-up 0.2.6

Dependencies:
msal 1.17.0
azure-mgmt-resource 20.0.0

Additional Context

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreyBespamyatnovcommented, Sep 28, 2022

Unfortunately, we can see the same issue with our Azure Pipeline

0reactions
navba-MSFTcommented, Oct 12, 2022

@AndreyBespamyatnov If you are seeing the same issue with Windows image in Azure Devops Pipeline then the same above plan can be done by implementing this via registry key using PS. You can run the below PS script for that:

New-ItemProperty -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage' -Name 'ACP' -Value '65001' -PropertyType String -Force;
New-ItemProperty -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage' -Name 'OEMCP' -Value '65001' -PropertyType String -Force;
New-ItemProperty -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage' -Name 'MACCP' -Value '65001' -PropertyType String -Force;

More Info here. Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnicodeEncodeError: 'charmap' codec can't encode characters
I was getting the same UnicodeEncodeError when saving scraped web content to a file. To fix it I replaced this code:
Read more >
CLIInternalError: 'ascii' codec can't encode character '\u2716 ...
I have a AZ CLI task that executes an AZ ACR BUILD. At the end of the ACR build I get this error...
Read more >
Change log for 4.6.62
... Bug 1872080: Add Dockerfile.rhel to match build configuration in ocp-build-data # ... Bug 1973599: Escape characters on ini file #1137 ...
Read more >
StandardID 4112 3059 3060 3061 3062 3063 3064 3065 ...
ASCII Printable Characters-Based Chinese Character Encoding for Internet Messages ... Building automation and control systems -- Part 5: Data communication ...
Read more >
https://huggingface.co/dalle-mini/dalle-mini/resol...
... together 601894 round 598558 project 595004 services 594042 founded 593972 radio 591872 design 590249 per 584600 position 584069 event 581922 southern ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found