UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' (copyright field)
See original GitHub issueHey folks,
I’ve been using fontmake on https://github.com/weiweihuanghuang/Work-Sans. This font uses a copyright symbol in the copyright field.
‘Copyright © 2015 by Wei Huang. All rights reserved.’
Fontmake didn’t like this. The traceback points to glyphsLib/builder.py", line 214, in generate_base_fonts
if copyright:
ufo.info.copyright = unicode(copyright.decode("utf-8"))
If I remove the copyright symbol, it will successfully convert the .glyphs into ufos.
I have the following dependencies installed:
python 2.7
defcon==0.1
fonttools==3.0
glyphsLib==1.0
robofab==1.2
wheel==0.24.0
If my dependencies are ok and I’m not doing something stupid, I’ll happily fix this. I’m guessing it could be the classic 2.7 encode/decode problem.
Regards, Marc
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
UnicodeEncodeError: 'ascii' codec can't encode character u ...
Read the Python Unicode HOWTO. This error is the very first example. Do not use str() to convert from unicode to encoded text...
Read more >Fix Python UnicodeEncodeError: 'ascii' codec can't encode ...
A very common Python error that is raised when working with unicode characters is the UnicodeEncodeError . UnicodeEncodeError: 'ascii' codec can't encode ......
Read more >'ascii' codec can't encode character in position | bobbyhadz
The Python "UnicodeEncodeError: 'ascii' codec can't encode character in position" occurs when we use the ascii codec to encode a string that contains...
Read more >How To Fix Python Error - UnicodeEncodeError: 'ascii' codec ...
This is a very common error UnicodeEncodeError: 'ascii' codec can't encode character u'xa0' in position x.
Read more >Python UnicodeEncodeError: 'ascii' codec can't encode ...
This error occurs when you pass a Unicode string containing non-English characters (Unicode characters beyond 128) to something that expects an ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you Cosimo!
Ok, the issue is because since #60 glyphsLib parser is decoding the input data using UTF-8 encoding so the parsed data is already unicode strings. That line in builder.py was still attempting to call
decode
on a unicode string, which on Python 3 is illegal, whereas on Python2 it encodes with default encoding (‘ascii’) before decoding with the specified encoding. That’s why it fails withUnicodeEncodeError
when attempting todecode
… I’ll send a patch.