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

Bug: UnicodeEncodeError when redirect stdout to a file #110

Closed
alarreine opened this issue Nov 15, 2018 · 0 comments · Fixed by #111
Closed

Bug: UnicodeEncodeError when redirect stdout to a file #110

alarreine opened this issue Nov 15, 2018 · 0 comments · Fixed by #111
Assignees
Labels

Comments

@alarreine
Copy link
Contributor

Description

I'm trying to use Halo in a CLI that can be called from a terminal directly or from a CI, when I try to redirect the stdout to a file I have this exception.

Example:

def my_cli_task:
    spinner = halo.Halo(enabled=True, spinner='dots')
    spinner.start(text="Starting")
    ...
    
    ...
    spinner.succeed('Complete')
    spinner.stop()

It works perfectly in the terminal but when I try to redirect the stdout to a file, it raise an exception.
e.g.:

$ ./my_example_cli_task.py > cli.log

System settings

  • Operating System: Ubuntu 18.04.1 LTS
  • Terminal in use: NA
  • Python version: Python 2.7.15rc1
  • Halo version: 0.0.21
  • pip freeze output:

Error

 Traceback (most recent call last):
  File "test.py", line 7, in <module>
    spin.start(text="Starting")
  File "/home/agustin/git/halo/halo/halo.py", line 423, in start
    self._render_frame()
  File "/home/agustin/git/halo/halo/halo.py", line 341, in _render_frame
    self._stream.write(output)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 166, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "/usr/local/lib/python2.7/dist-packages/colorama/ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
UnicodeEncodeError: 'ascii' codec can't encode character u'\u280b' in position 0: ordinal not in range(128)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/agustin/git/halo/halo/halo.py", line 81, in clean_up
    self.stop()
  File "/home/agustin/git/halo/halo/halo.py", line 440, in stop
    self._spinner_thread.join()
  File "/usr/lib/python2.7/threading.py", line 929, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/agustin/git/halo/halo/halo.py", line 81, in clean_up
    self.stop()
  File "/home/agustin/git/halo/halo/halo.py", line 440, in stop
    self._spinner_thread.join()
  File "/usr/lib/python2.7/threading.py", line 929, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started

Expected behaviour

Print the my CLI log to a file

Steps to recreate

Redirect the stdout to file

People to notify

@alarreine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants