LPgenerator / mattermost_bot

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

Cannot send non-ascii characters? #31

Closed bagage closed 7 years ago

bagage commented 7 years ago

I'm trying to use the following code:

    message.send(message.get_username() + "éhoh")

But it raises an exception:

ERROR:mattermost_bot.dispatcher:'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mattermost_bot/dispatcher.py", line 71, in dispatch_msg
    func(Message(self._client, msg, self._pool), *args)
  File "test.py", line 63, in aide
    message.send(message.get_username() + "éhoh")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Unhandled exception in thread started by <bound method WorkerPool.do_work of <mattermost_bot.utils.WorkerPool object at 0x7fad33d8df90>>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/mattermost_bot/utils.py", line 31, in do_work
    self.func(msg)
  File "/usr/local/lib/python2.7/dist-packages/mattermost_bot/dispatcher.py", line 76, in dispatch_msg
    reply += '```\n%s\n```' % traceback.format_exc()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 283: ordinal not in range(128)

However it does not raise an exception if I simply use message.send("éhoh") nor message.send(message.get_username() + "hello").

Any idea?

gotlium commented 7 years ago

Possible you can find answer to this question on issue #6

bagage commented 7 years ago

Thanks for the pointers @gotlium. I found a solution yet, which is to use printf.format instead of printf(+):

- message.send(message.get_username() + "éhoh")
+ message.send("{} {}".format(message.get_username(), "éhoh")