UnicodeEncodeError: 'ascii' codec can't encode character
See original GitHub issueHi Peter, I’ve created an html document with bootstrap styling and when I try and run Premailer from the CLI I get the following error:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/oldo/Python/virtual-environments/AMS-Journal/lib/python2.7/site-packages/premailer/__main__.py", line 142, in <module>
sys.exit(main(sys.argv[1:]))
File "/Users/oldo/Python/virtual-environments/AMS-Journal/lib/python2.7/site-packages/premailer/__main__.py", line 137, in main
options.outfile.write(p.transform(pretty_print=options.pretty))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 106688: ordinal not in range(128)
I have tried everything that I can think of to try and avoid this, but can’t seem to make any progress. What would usually cause this error and do you know a way to fix it? Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
UnicodeEncodeError: 'ascii' codec can't encode character ...
The issue is that when you call str(), python uses the default character encoding to try and encode the bytes you gave it,...
Read more >Fix Python UnicodeEncodeError: 'ascii' codec can't encode ...
The UnicodeEncodeError we reproduced earlier, is caused due to the fact that when str() method is called, the interpreter will use the default...
Read more >'ascii' codec can't encode character in position
The Python "UnicodeEncodeError: 'ascii' codec can't encode character in position" occurs when we use the ascii codec to encode a string that ...
Read more >UnicodeEncodeError: 'ascii' codec can't encode character'
Fix – UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0′: · Set the Python encoding to UTF-8. · Set the environment variables correctly in...
Read more >'ascii' codec can't encode character '\xe9' in position 117: ...
Description. UnicodeEncodeError: 'ascii' codec can't encode character '\xe9'. Expected behavior. No response. pip version.
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 Free
Top 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
I was running into a similar issue:
https://github.com/pixelb/scripts/blob/4d075026866dff074749f938c111c7a0478309c1/scripts/ansi2html.sh
Found this article http://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html and the following command worked:
Python 2.7.10, premailer 3.0.1. It looks like you need to use the -o option to get the bug; if I omit the -o, it prints the output to stdout, with the degree sign rendered as unicode. Here’s a simple script to reproduce:
When I run that, I get the exception.