UnicodeEncodeError: charmap codec cannot encode character

Python throws this away when using the wolfram alpha api:

Traceback (most recent call last):
  File "c:\Python27\lib\threading.py", line 530, in __bootstrap_inner
  File "c:\Python27\lib\site-packages\Skype4Py\utils.py", line 225, in run
    handler(*self.args, **self.kwargs)
  File "s.py", line 38, in OnMessageStatus
    if body[0:5] == '!math':wolfram(body[5:], '')
  File "s.py", line 18, in wolfram
    print "l: "+l
  File "c:\Python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xd7' in position 3
: character maps to <undefined>


how can i solve this?


source to share

1 answer

It looks like you are passing high byte data to the API and it doesn't like that (\ xd7 is the "Times" character, looks like X). I'm not sure what printing is for, but changing that setting should be, print "l: " + repr(l)

or print "l: ", l

at least will allow you to get past the above error, assuming you don't want to go about converting the body to unicode (I'm guessing that's not ...).

If that doesn't work, we'll need more information. Where does your entrance come from? Is the body unicode or a byte string? Are you using python 2.7 or 3.x?



All Articles