When I try to print a Unicode string in a Windows console, I get a UnicodeEncodeError: \'charmap\' codec can\'t encode character ....
error. I assume this is b
TL;DR:
print(yourstring.encode('ascii','replace'));
I ran into this myself, working on a Twitch chat (IRC) bot. (Python 2.7 latest)
I wanted to parse chat messages in order to respond...
msg = s.recv(1024).decode("utf-8")
but also print them safely to the console in a human-readable format:
print(msg.encode('ascii','replace'));
This corrected the issue of the bot throwing UnicodeEncodeError: 'charmap'
errors and replaced the unicode characters with ?
.