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.

UnicodeEncodeError on some Linux'es (ubuntu 16.04 and Slackware 14.2)

See original GitHub issue
In [17]: from alive_progress import alive_bar

In [18]: def pretty_sleep(sleep_time: int, bar='filling'):
    ...:     """pretty sleep with progress bar"""
    ...:     with alive_bar(int(sleep_time), bar=bar) as bar:
    ...:         for i in range(int(sleep_time)):
    ...:             time.sleep(0.001)
    ...:             bar()
    ...:

In [19]: pretty_sleep(100)
Exception in thread Thread-1851:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/home/rjosyula/x/lib/python3.5/site-packages/alive_progress/progress.py", line 100, in run
    alive_repr(next(player))
  File "/home/rjosyula/x/lib/python3.5/site-packages/alive_progress/progress.py", line 115, in alive_repr
    sys.__stdout__.write(line + (spin and '\r' or '\n'))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 43-45: ordinal not in range(256)

---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-19-5b2d8b0fde03> in <module>
----> 1 pretty_sleep(100)

<ipython-input-18-920a2b64dd16> in pretty_sleep(sleep_time, bar)
      4         for i in range(int(sleep_time)):
      5             time.sleep(0.001)
----> 6             bar()
      7

/usr/lib/python3.5/contextlib.py in __exit__(self, type, value, traceback)
     64         if type is None:
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:
     68                 return

~/x/lib/python3.5/site-packages/alive_progress/progress.py in alive_bar(total, title, calibrate, **options)
    257
    258     end, run.text, run.stats = True, '', stats_end
--> 259     alive_repr()

~/x/lib/python3.5/site-packages/alive_progress/progress.py in alive_repr(spin)
    113             if line_len < run.last_line_len:
    114                 clear_traces()
--> 115             sys.__stdout__.write(line + (spin and '\r' or '\n'))
    116             sys.__stdout__.flush()
    117

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-40: ordinal not in range(256)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
mborsalinocommented, Feb 17, 2022

@TheTechRobo: the problem is that when code is distributed there’s no guarantee regarding the environment that is going to be used.

This is not an issue for my particular case because users of my code never start Python directly, but rather via a wrapper script. So I have the freedom to set the environment in the wrapper script and be done with it.

Others might want to write their own applications/modules using alive-progress. When they distribute the module they have no control over the environment where it’s going to be used.

A simple warning regarding this potential issue in alive_progress documentation could suffice. A better approach would be to try to catch the non-UTF-8 encoding and default to a “classic” progress bar appearance. But this is up to @rsalmei since he’s the maintainer.

2reactions
MurdoMaclachlancommented, Jan 19, 2021

I just added bar='classic' as well, after realising that these are two different configurations. Using both of these, the progress bar works perfectly as the classic settings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

configuration can not find gtk3 and gtk2 , unicode will not be ...
Hello, I use slackware 14.2 and trying to build wxWidget 3.0.2 which required gtk. Ther are three packages and versions of gtk installed...
Read more >
slackware:localization - SlackDocs
Note that Slackware is not fully Unicode-prepared. Some applications (like the man pages) will not properly display Unicode text. For some ...
Read more >
[slackware-security] Slackware 14.2 kernel - Vulners
Description. New kernel packages are available for Slackware 14.2 to fix security issues. Here are the details from the Slackware 14.2 ...
Read more >
UnicodeEncodeError on Linux but not on Windows [duplicate]
It's very likely that your locale and/or environment is broken, not installed, not set or set to C . Python uses the locale...
Read more >
Slackware 14.2 Released, Still Systemd-Free - Slashdot
Slackware is noted for being the most Unix-like of all Linux ... gonna be moving to 16.04 due to the infestation of systemd...
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