gowner
gowner

Reputation: 337

Python decoding fails at Wikipedia article?

I'm still writing a program which uses data from Wikipedia pages. However, when I execute the code below, I get this exception:

UnicodeEncodeError: 'charmap' codec can't encode characters in position 30-31: character maps to <undefined>

Here is the code:

import wikipedia
print(wikipedia.summary("Barack Obama", 1))

I looked at the Wikipedia source code and I could only find UTF-8, but that is my standard decoding method anyways. So what I learn from this is that Wikipedia is using some strange symbols that somehow are contained in UTF-8 but somehow are not at the same time. How do I best deal with this if I still want to display the text?

Upvotes: 2

Views: 243

Answers (1)

Gerard Rozsavolgyi
Gerard Rozsavolgyi

Reputation: 5064

Your code runs perfectly on Mac OS X and Linux with Python3. I suspect you are using Windows with a non-UTF8 terminal. Change your terminal settings with :

chcp 65001

You might need to use Lucida Console font

Upvotes: 2

Related Questions