0

I'm using Python 2.7 and trying to work with the following code

import wikipedia

input = raw_input("Question: ")
print wikipedia.summary(input)

I see this error when the code is run:

Traceback (most recent call last): File "wik.py", line 5, in print wikipedia.summary(input) File "C:\Anaconda2\lib\encodings\cp437.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position 38: character maps to undefined

How can I fix this? Thanks in advance.

Daniel H
  • 7,223
  • 2
  • 26
  • 41
DEV Bob
  • 31
  • 1
  • 4

1 Answers1

1

Python 2 defaults to ASCII, which only maps characters between \u0000 and \u007F1. You need to use a different encoding in order to properly get this character (\u2013 is a long dash) and many others outside of ASCII.

Using UTF-8 should work for you, and I believe this print statement will properly output text:

print wikipedia.summary(input).encode("utf8")

For more information on this, check this similar question: UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 3 2: ordinal not in range(128).

mjmccolgan
  • 27
  • 5