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

-d fails on unicode when output redirected #15

Open
dohliam opened this issue Mar 14, 2015 · 0 comments
Open

-d fails on unicode when output redirected #15

dohliam opened this issue Mar 14, 2015 · 0 comments

Comments

@dohliam
Copy link

dohliam commented Mar 14, 2015

Epub files containing unicode work beautifully when epub.py is called without command-line options. They also works perfectly well (at least in unicode locales) when the output is simply dumped to the screen. However, in most cases when dumping the contents of an entire ebook one would probably want to redirect the output, e.g., to a screen reader like less or to a file. The -d option fails in both these cases with the dreaded Python2 ascii codec error:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)

As explained here, this is because python2 treats printing to the terminal differently than redirecting output.

Solution
I was able to fix this problem by using kitchen.text.converters.getwriter() as suggested in the document above. Normal functioning of the program does not seem to have been affected, and unicode files now work as expected in all cases (including -d).

dohliam added a commit to dohliam/epub that referenced this issue Mar 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant