havardgulldahl / jottalib

A library to access files stored at jottacloud.com.
GNU General Public License v3.0
83 stars 19 forks source link

Don't use utf-8 in console output on windows #85

Closed antonhagg closed 8 years ago

antonhagg commented 8 years ago

When running the jotta-dowload there seems to be an issue with the progress bar. The error I get is:

C:\Users\XX>jotta-download Jottacloud.pdf
Traceback (most recent call last):
  File "C:\Python27\Scripts\jotta-download-script.py", line 9, in <module>
    load_entry_point('jottalib==0.4.1.post1', 'console_scripts', 'jotta-download')()
  File "c:\python27\lib\site-packages\jottalib\cli.py", line 229, in download
    with ProgressBar(expected_size=total_size) as bar:
  File "c:\python27\lib\site-packages\clint\textui\progress.py", line 63, in __init__
    self.show(0)
  File "c:\python27\lib\site-packages\clint\textui\progress.py", line 87, in show
    self.expected_size, self.etadisp))
  File "c:\python27\lib\site-packages\clint\packages\colorama\ansitowin32.py", line 34, in write
    self.__convertor.write(text)
  File "c:\python27\lib\site-packages\clint\packages\colorama\ansitowin32.py", line 115, in write
    self.write_and_convert(text)
  File "c:\python27\lib\site-packages\clint\packages\colorama\ansitowin32.py", line 142, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "c:\python27\lib\site-packages\clint\packages\colorama\ansitowin32.py", line 147, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\python27\lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-32: character maps to <undefined>

Commenting out line 229 and 233 It works perfectly.

antonhagg commented 8 years ago

Removing empty_char='○', filled_char='●' in Cli.py seems to fix the issue.

havardgulldahl commented 8 years ago

Ok, so the Windows command line doesn't support unicode characters.

Without really going into this, I would say that an easy fix might be to run a if platform.system()=='Windows' check, and disable the offending chars if True.