View Single Post
Old 07-14-2015, 05:50 PM   #1177
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,893
Karma: 6120478
Join Date: Nov 2009
Device: many
Hi,

That error happens in python 2.7 when the terminal encoding is not properly set to handle utf-8 characters. It is actually the copyright symbol in the "print" that is the issue.

If you are redirecting the output of the program in any way, python 2.7 is stupid enough to set sys.stdout to None. But that said, there is code in kindleunpack.py that should take care of this case for python 2.7.

Code:
if PY2:
    range = xrange
    # since will be printing unicode under python 2 need to protect
    # against sys.stdout.encoding being None stupidly forcing forcing ascii encoding
    if sys.stdout.encoding is None:
        sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
    else:
        encoding = sys.stdout.encoding
        sys.stdout = codecs.getwriter(encoding)(sys.stdout)
If you have python 3.4 available, could you please test with it to see if it barfs about the same thing?

Thanks,

Kevin


Quote:
Originally Posted by jemc View Post
I'm getting an odd little crash out of version 0.80. When I run kindleunpack.py from the command-line without redirecting output to a standard port or file this happens:

Spoiler:
C:\Temp\KU080>python lib\kindleunpack.py -h
KindleUnpack v0.80
Traceback (most recent call last):
File "lib\kindleunpack.py", line 1016, in <module>
sys.exit(main())
File "lib\kindleunpack.py", line 951, in main
print(" Based on initial mobipocket version Copyright © 2009 Charles M. H
annum <root@ihack.net>")
File "C:\Python27\lib\codecs.py", line 357, in write
data, consumed = self.encode(object, self.errors)
File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xa9' in position 4
9: character maps to <undefined>


The crash occurs regardless of command-line switches used.

When I redirect output: "python lib\kindleunpack.py -h >log.txt" kindleunpack.py executes correctly.

Version 0.77 works fine on my box in both the above cases.

I'm running Win8.1 64bit and tried both current ActivePython & Python.org v2.x & v3.x 32&64bit pythons with v0.80 - no joy.

No worries though, I've got my workaround for now.
KevinH is offline   Reply With Quote