Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix UnicodeDecodeError: 'ascii' codec can't decode byte #492

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

Closed
wants to merge 1 commit into from
Closed

Fix UnicodeDecodeError: 'ascii' codec can't decode byte #492

wants to merge 1 commit into from

Conversation

cgohlke
Copy link
Contributor

@cgohlke cgohlke commented Sep 24, 2011

On Windows the example font_table_ttf.py fails with

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc1 in position 0: ordinal not in range(128)

@efiring
Copy link
Member

efiring commented Sep 24, 2011

I'm not sure this is the right fix. I don't understand why the conversion to unicode is needed in the first place; and even if it is, why does it make sense to hardwire the encoding to windows-1252?

@mdboom
Copy link
Member

mdboom commented Sep 24, 2011

If the user put non-ascii characters in an 8-bit string, there's nothing we can safely do -- there's no way to assume the encoding that will work for everyone. If that's what the user wants to do, they must pass Unicode strings. I think this should remain an error (though we could improve the error message if we want).

@efiring
Copy link
Member

efiring commented Sep 25, 2011

Christoph, your solution will break if a unicode string is supplied as an argument to is_math_text:

xx = unicode(u"abc$", "windows-1252")

yields

TypeError: decoding Unicode is not supported

Simply removing the call to unicode() solves the immediate problem--it makes the example work--and I don't see anything wrong with it. But Mike wrote is_math_text() with the call to unicode(), so I would not want to delete it without his concurrence. All this is made more complicated by the huge byte/string/unicode change in Py 3.x.

Eric

@cgohlke cgohlke closed this Sep 25, 2011
@mdboom
Copy link
Member

mdboom commented Sep 26, 2011

See pull request #494 for an alternative solution.

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

Successfully merging this pull request may close these issues.

3 participants