+2 votes
in Programming Languages by (54.5k points)

myopener = MyOpener()
pagedata = myopener.open(pageurl2).read().decode('UTF-8')
print (pagedata)

I have the above code to read a webpage, but the print statement give the following error...

Python 3.5 - UnicodeEncodeError: 'charmap' codec can't encode character '\u2014' in position 256: character maps to <undefined>

How to fix it?

1 Answer

+1 vote
by (54.5k points)
edited by

The problem seems to be related to Windows operating system. Open the command terminal and type the following two commands in sequence.. It should fix the error.

chcp 65001
set PYTHONIOENCODING=utf-8

...