+2 votes
in Programming Languages by (71.8k 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

+2 votes
by (71.8k points)
selected by
 
Best answer

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

...