Skip to content
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

rich library - python UnicodeEncodeError while stopping/starting module #1250

Closed
matthieumarrast opened this issue Jan 5, 2022 · 3 comments

Comments

@matthieumarrast
Copy link
Contributor

version : Metwork 1.2
OS : CentOS 6.10

  • Issue

While stopping/starting a module, the rich library raises a UnicodeEncodeError, see below :

***********************************
*****     STOPPING MFDATA     *****
***********************************
- Uninstalling module crontab...                           [ OK ]
- Scheduling stop of nginx                                 [ ERROR ]
Traceback (most recent call last):
  File "/opt/metwork-mfext-1.2/bin/_circus_schedule_stop_watcher.py", line 17, in <module>
    client.stop_watcher(name=name)
  File "/opt/metwork-mfext-1.2/lib/mfext/circus.py", line 102, in stop_watcher
    t = progress.add_task(txt, total=timeout)
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/rich/progress.py", line 668, in add_task
    self.refresh()
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/mfutil/cli.py", line 401, in refresh
    return Progress.refresh(self, *args, **kwargs)
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/rich/progress.py", line 588, in refresh
    self.console.print(self._live_render)
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/rich/console.py", line 346, in __exit__
    self._exit_buffer()
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/rich/console.py", line 337, in _exit_buffer
    self._check_buffer()
  File "/opt/metwork-mfext-1.2/opt/python3/lib/python3.9/site-packages/rich/console.py", line 834, in _check_buffer
    self.file.write(text)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 62-73: ordinal not in range(256)
  • Reason

standard output encoding is not utf-8 :

$ python -c "import sys; print(sys.stdout.encoding)"
iso8859-1

when encoding is not set along with the locale :

$ locale
LANG=fr_FR
LC_CTYPE="fr_FR"
...
  • Bypass

In the home dir (~) of the module, execute :

echo "export PYTHONIOENCODING=utf-8" > .metwork.custom_profile

and reload the module.

  • Possible perennial solution(s)
  1. update rich library, the last version catch the error and display a clear message : "You may need to add PYTHONIOENCODING=utf-8 to your environment"
  2. add by default PYTHONIOENCODING=utf-8 in the environment variables of the module(s)
@matthieumarrast
Copy link
Contributor Author

cf. issue Textualize/rich#212, improved in rich v5.1.0 (2020-08-08)

@matthieumarrast
Copy link
Contributor Author

maybe we can add the env variable to mfext/adm/templates/profile ?

@thefab
Copy link
Member

thefab commented Jan 6, 2022

to avoid any regression, maybe it's better to add export PYTHONIOENCODING=utf-8 at the very beginning of mfxxx.start/stop/init/status script in mfext adm/templates

metworkbot pushed a commit that referenced this issue Jan 7, 2022
mergify bot pushed a commit that referenced this issue Jan 7, 2022
#1254)

…ndard output encoding is not utf-8

Close: #1250
(cherry picked from commit cb5b3fe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants