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 throws UnicodeEncodeError: 'ascii' codec can't encode character

See original GitHub issue

Describe the bug We’re running az acr build ... from our jenkins slaves that also run tests. If the docker build process returns unicode characters, az throws an UnicodeDecodeError (full traceback below). When running the build process interactively on my local machine i see the line that is causing the error: npm WARN deprecated babel-preset-es2015@6.24.1: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! I suspect the emoji is causing the error because the library colorama used in az handles the output different for a non-tty environment.

To Reproduce trigger a az acr build with a Dockerfile that causes unicode output in e.g. jenkins (non-tty environment).

Expected behavior i’d expect the build to succeed and the unicode characters returned as well

Environment summary rpm installation, bash, non interactive. version:

azure-cli (2.0.32)

acr (2.0.24)
acs (2.0.32)
advisor (0.5.1)
ams (0.1.0)
appservice (0.1.32)
backup (1.1.1)
batch (3.2.2)
batchai (0.2.2)
billing (0.1.8)
cdn (0.0.14)
cloud (2.0.13)
cognitiveservices (0.1.13)
command-modules-nspkg (2.0.1)
configure (2.0.15)
consumption (0.3.1)
container (0.1.23)
core (2.0.32)
cosmosdb (0.1.21)
dla (0.0.19)
dls (0.0.21)
dms (0.0.1)
eventgrid (0.1.12)
eventhubs (0.1.3)
extension (0.0.13)
feedback (2.1.1)
find (0.2.9)
interactive (0.3.20)
iot (0.1.20)
keyvault (2.0.21)
lab (0.0.22)
monitor (0.1.6)
network (2.1.0)
nspkg (3.0.2)
profile (2.0.24)
rdbms (0.2.2)
redis (0.2.13)
reservations (0.1.2)
resource (2.0.28)
role (2.0.23)
servicebus (0.1.2)
servicefabric (0.0.12)
sql (2.0.25)
storage (2.0.32)
vm (2.0.31)

Python location '/usr/lib64/az/bin/python'
Extensions directory '/var/lib/jenkins/.azure/cliextensions'

Python (Linux) 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

Legal docs and information: aka.ms/AzureCliLegal

Additional context this seems to be related: https://github.com/tartley/colorama/issues/36

full output:

az acr build -r myreg --no-push false -t myreg.azurecr.io/repo/myapp:master -f ./Dockerfile .
Sending build context (43.398 KiB) to ACR.
Queued a build with build ID: aah
Waiting for a build agent...
time="2018-05-22T21:11:59Z" level=info msg="Running command docker login -u 00000000-0000-0000-0000-000000000000 --password-stdin myreg.azurecr.io"
Login Succeeded
time="2018-05-22T21:12:01Z" level=info msg="Untarring to /root/acr-builder/src"
time="2018-05-22T21:12:01Z" level=info msg="Running command docker build --pull -f ./Dockerfile -t myreg.azurecr.io/repo/myapp:master ."
Sending build context to Docker daemon  220.2kB

Step 1/8 : FROM node:carbon
carbon: Pulling from library/node
3d77ce4481b1: Already exists
534514c83d69: Already exists
d562b1c3ac3f: Already exists
4b85e68dc01d: Already exists
f6a66c5de9db: Already exists
7a4e7d9a081d: Already exists
49f75af57b99: Pulling fs layer
454abe4fb374: Pulling fs layer
454abe4fb374: Verifying Checksum
454abe4fb374: Download complete
49f75af57b99: Verifying Checksum
49f75af57b99: Download complete
49f75af57b99: Pull complete
454abe4fb374: Pull complete
Digest: sha256:19efc0ee886057870334b4b4b4a505ea8a158d135f592cc367ab8840b684f6c0
Status: Downloaded newer image for node:carbon
 ---> 037acc6a00bc
Step 2/8 : WORKDIR /usr/src/app
Removing intermediate container ade8e4293757
 ---> 5fa54edc3ae3
Step 3/8 : COPY package*.json ./
 ---> 295c9eeaf7fc
Step 4/8 : RUN npm install
 ---> Running in 6846edad6a09
npm WARN deprecatedERROR: 'ascii' codec can't encode character u'\U0001f64c' in position 29: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/lib64/az/lib/python2.7/site-packages/knack/cli.py", line 197, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 332, in execute
    six.reraise(*sys.exc_info())
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 306, in execute
    result = cmd(params)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 167, in __call__
    return super(AzCliCommand, self).__call__(*args, **kwargs)
  File "/usr/lib64/az/lib/python2.7/site-packages/knack/commands.py", line 109, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/__init__.py", line 420, in default_command_handler
    result = op(**command_args)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/command_modules/acr/build.py", line 330, in acr_build
    return acr_build_show_logs(client, build_id, registry_name, resource_group_name, True)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/command_modules/acr/build.py", line 71, in acr_build_show_logs
    raise_error_on_failure=raise_error_on_failure)
  File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/command_modules/acr/build.py", line 132, in _stream_logs
    print(flush.decode('utf-8', errors='ignore'))
  File "/usr/lib64/az/lib/python2.7/site-packages/colorama/ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "/usr/lib64/az/lib/python2.7/site-packages/colorama/ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "/usr/lib64/az/lib/python2.7/site-packages/colorama/ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "/usr/lib64/az/lib/python2.7/site-packages/colorama/ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
UnicodeEncodeError: 'ascii' codec can't encode character u'\U0001f64c' in position 29: ordinal not in range(128)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jodokcommented, Jul 20, 2018

i created a fix upstream, but unfortunately this isn’t merged yet: https://github.com/tartley/colorama/pull/167 - meanwhile we ended up patching the library in our own deployments - which works so far.

0reactions
majidaldocommented, Nov 7, 2021

on windows, set PYTHONIOENCODING=utf-8. i’m using the latest cli (py39, pip installed). so stupid we’re dealing with this in 2021.

i didn’t do too much investigation but i think it’s more fundamentally with colorama.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure CLI : UnicodeEncodeError: 'ascii' codec can't encode ...
I have installed azure-cli using pip2 on alpine. When using azure-cli, in "vm create" command, I am getting above error. az login #worked...
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 >
Fix Python UnicodeEncodeError: 'ascii' codec can't encode ...
A very common Python error that is raised when working with unicode characters is the UnicodeEncodeError . UnicodeEncodeError: 'ascii' codec can't encode ......
Read more >
'Utf-8' Codec Can't Decode Byte 0X8E In Position - ADocLib
Running Az Cli Commands In Cloud Shell Fails With Unicodedecodeerror: 'Utf-8' ... Here is the traceback: 'ascii' codec can't encode character '\u2716' in ......
Read more >
How To Fix Python Error - UnicodeEncodeError: 'ascii' codec ...
Fix – UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0′: · Set the Python encoding to UTF-8. · Set the environment variables correctly in...
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