dailykindle icon indicating copy to clipboard operation
dailykindle copied to clipboard

Encoding error

Open sulazix opened this issue 10 years ago • 1 comments

Hi, Firstly thanks for your script ! I just got some problems while importing French article ( in UTF-8 ) it was unable to write properly the output in "render_and_write" with some typical french char (à,é,à etc...) I solved this by adding :

template = templates_env.get_template(template_name)
f = open(path.join(output_dir, output_name), "w")
f.write(template.render(**context).encode('UTF-8')) <- add encode here Line 97
f.close()

Is it possible to commit it ? Some other people got the same issue on http://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20/9942822#9942822 "In case someone else gets confused by this, I found a strange thing: my terminal uses utf-8, and when I print my utf-8 strings it works nicely. However when I pipe my programs output to a file, it throws a UnicodeEncodeError. In fact, when output is redirected (to a file or a pipe), I find that sys.stdout.encoding is None! Tacking on .encode('utf-8') solves the problem. " drevick

BB Thanks again for your script ! Have a nice day Sulazix

sulazix avatar Aug 08 '14 00:08 sulazix

Just forget the initial bug trace if you want it: File "dailykindle.py", line 97, in render_and_write f.write(template.render(**context)) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 1016: ordinal not in range(128) -- (u'\xe0' is "à")

sulazix avatar Aug 08 '14 00:08 sulazix