question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' (copyright field)

See original GitHub issue

Hey 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:closed
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
m4rc1ecommented, Jul 25, 2016

Thank you Cosimo!

0reactions
anthrotypecommented, Jul 25, 2016

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 with UnicodeEncodeError when attempting to decode… I’ll send a patch.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found