Poetry: 1.0.0b1 crashes with unicode encode error when displaying help

Created on 1 Oct 2019  路  2Comments  路  Source: python-poetry/poetry

  • [x] I am on the latest Poetry version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Ubuntu 18.04
  • Poetry version: 1.0.0b1
  • Link of a Gist with the contents of your pyproject.toml file: Issue is not related to a pyproject.toml file

Issue

The current 1.0.0 beta release crashes when running poetry with --help or without arguments:

$ poetry
Poetry version 1.0.0b1

USAGE

[UnicodeEncodeError]
'ascii' codec can't encode character '\xa0' in position 30: ordinal not in range(128)

I've only seen this in a Docker container, it works correctly on my desktop.

This Dockerfile reproduces it:

FROM ubuntu:bionic-20190912.1

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        python3.6 python3-pip python3-venv && \
    pip3 install setuptools wheel && \
    pip3 install poetry==1.0.0b1

Steps:

  1. Create ./Dockerfile in a directory containing the above
  2. From the dir, run $ sudo docker build -t poetry-unicode-issue .
  3. Execute poetry in the image as follows:
$ sudo docker run poetry-unicode-issue poetry --help -vvv
Poetry version 1.0.0b1

USAGE

[UnicodeEncodeError]
'ascii' codec can't encode character '\xa0' in position 22: ordinal not in range(128)

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/clikit/console_application.py", line 132, in run
    status_code = command.handle(parsed_args, io)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/command/command.py", line 173, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/usr/local/lib/python3.6/dist-packages/clikit/handler/help/help_text_handler.py", line 29, in handle
    usage.render(io)
  File "/usr/local/lib/python3.6/dist-packages/clikit/ui/help/abstract_help.py", line 31, in render
    layout.render(io, indentation)
  File "/usr/local/lib/python3.6/dist-packages/clikit/ui/layout/block_layout.py", line 42, in render
    element.render(io, self._indentations[i] + indentation)
  File "/usr/local/lib/python3.6/dist-packages/clikit/ui/components/labeled_paragraph.py", line 70, in render
    + '
'"
  File "/usr/local/lib/python3.6/dist-packages/cleo/io/io_mixin.py", line 55, in write
    super(IOMixin, self).write(string, flags)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/io/io.py", line 58, in write
    self._output.write(string, flags=flags)
  File "/usr/local/lib/python3.6/dist-packages/clikit/api/io/output.py", line 61, in write
    self._stream.write(to_str(formatted))
  File "/usr/local/lib/python3.6/dist-packages/clikit/io/output_stream/stream_output_stream.py", line 24, in write
    self._stream.write(string)

The default encoding seems to be detected correctly:

$ python3 -c 'import sys; print(sys.getdefaultencoding())'
utf-8
Bug

Most helpful comment

This is not a poetry issue. The problem here is the container locale.

$ docker run --rm -it ubuntu:bionic-20190912.1 locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

When the default "C" (POSIX) locale is used, python 3 does not like it. See https://bugs.python.org/issue19846 for more information.

If you want to keep using python 3.6, then you can add this to your Dockerfile to get it working.

ENV LANG C.UTF-8

As per PEP-538 and PEP-540, python 3.7 will work out of the box.

All 2 comments

This is not a poetry issue. The problem here is the container locale.

$ docker run --rm -it ubuntu:bionic-20190912.1 locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

When the default "C" (POSIX) locale is used, python 3 does not like it. See https://bugs.python.org/issue19846 for more information.

If you want to keep using python 3.6, then you can add this to your Dockerfile to get it working.

ENV LANG C.UTF-8

As per PEP-538 and PEP-540, python 3.7 will work out of the box.

Ah OK, thanks for that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhrmnn picture jhrmnn  路  3Comments

ghost picture ghost  路  3Comments

Euphorbium picture Euphorbium  路  3Comments

probablykasper picture probablykasper  路  3Comments

thmo picture thmo  路  3Comments