googlefonts / fontdiffenator

Font comparison tool
Apache License 2.0
81 stars 13 forks source link

UnicodeEncodeError somewhere in `render_string` #51

Closed graphicore closed 5 years ago

graphicore commented 5 years ago
Traceback (most recent call last):
  File "worker-launcher.py", line 198, in consume
    run()
  File "/var/python/worker/diffenator.py", line 232, in run
    run_diffenator(fonts['before'], fonts['after'], self._out_dir, DIFFENATOR_THRESHOLDS['normal'])
  File "/var/python/worker/diffenator.py", line 89, in func_wrapper
    *args, **kwargs)
  File "/var/python/worker/diffenator.py", line 109, in run_diffenator
    diff = DiffFonts(font_before, font_after, settings=thresholds)
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 82, in __init__
    self.glyphs(self._settings["glyphs_thresh"])
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 201, in glyphs
    thresh=threshold, render_diffs=render_diffs)
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 35, in timed
    result = method(*args, **kw)
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 317, in diff_glyphs
    scale_upms=scale_upms, render_diffs=render_diffs)
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 355, in _modified_glyphs
    diff = diff_rendering(font_before, font_after, glyph['string'], glyph['features'])
  File "/usr/local/lib/python3.6/dist-packages/diffenator/diff.py", line 371, in diff_rendering
    img_before = render_string(font_before, string, features)
  File "/usr/local/lib/python3.6/dist-packages/diffenator/utils.py", line 27, in render_string
    img = StringIO(subprocess.check_output(cmd))
  File "/usr/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1275, in _execute_child
    restore_signals, start_new_session, preexec_fn)
UnicodeEncodeError: 'ascii' codec can't encode character '\xac' in position 7: ordinal not in range(128)
davelab6 commented 5 years ago

Python 3 and still this happens?

graphicore commented 5 years ago

This was a locale configuration problem of my Docker image. In the Dockerfile setting the environment variable LANG to C.UTF-8 helped:

ENV LANG C.UTF-8
# also an option:
# ENV PYTHONIOENCODING=UTF-8