LPgenerator / mattermost_bot

MatterBot - A chat bot for MatterMost (http://www.mattermost.org).
MIT License
211 stars 60 forks source link

UnicodeEncodeError in text._gen_at_message function #40

Open he2ss opened 7 years ago

he2ss commented 7 years ago

Hello,

Thank you for this great lib.

I have this issue when the function _get_at_message return the text :

File "/home/hess/projects/venv/local/lib/python2.7/site-packages/mattermost_bot/dispatcher.py", line 195, in _gen_at_message
    return '@{}: {}'.format(self.get_username(), text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 33: ordinal not in range(128)

I don't know why, but the content of "text" variable isn't encode in utf-8. To fix this issue, text variable should be encoded in utf-8

    def _gen_at_message(self, text):
        return '@{}: {}'.format(self.get_username(), text.encode('utf-8'))